Merge pull request #8435 from tk0miya/8434_autodoc_type_aliases_for_variables

Fix #8434: autodoc_type_aliases does not effect to variables
This commit is contained in:
Takeshi KOMIYA 2020-11-17 22:42:38 +09:00 committed by GitHub
commit 5df381e8e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 2 deletions

View File

@ -38,6 +38,8 @@ Bugs fixed
* #4606: autodoc: the location of the warning is incorrect for inherited method
* #8105: autodoc: the signature of class constructor is incorrect if the class
is decorated
* #8434: autodoc: :confval:`autodoc_type_aliases` does not effect to variables
and attributes
Testing
--------

View File

@ -1702,7 +1702,8 @@ class DataDocumenter(ModuleLevelDocumenter):
if not self.options.annotation:
# obtain annotation for this data
try:
annotations = get_type_hints(self.parent)
annotations = get_type_hints(self.parent, None,
self.config.autodoc_type_aliases)
except NameError:
# Failed to evaluate ForwardRef (maybe TYPE_CHECKING)
annotations = safe_getattr(self.parent, '__annotations__', {})
@ -2093,7 +2094,8 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
if not self.options.annotation:
# obtain type annotation for this attribute
try:
annotations = get_type_hints(self.parent)
annotations = get_type_hints(self.parent, None,
self.config.autodoc_type_aliases)
except NameError:
# Failed to evaluate ForwardRef (maybe TYPE_CHECKING)
annotations = safe_getattr(self.parent, '__annotations__', {})

View File

@ -4,6 +4,9 @@ from typing import overload
myint = int
#: docstring
variable: myint
def sum(x: myint, y: myint) -> myint:
"""docstring"""
@ -23,3 +26,10 @@ def mult(x: float, y: float) -> float:
def mult(x, y):
"""docstring"""
return x, y
class Foo:
"""docstring"""
#: docstring
attr: myint

View File

@ -700,6 +700,19 @@ def test_autodoc_type_aliases(app):
'.. py:module:: target.annotations',
'',
'',
'.. py:class:: Foo()',
' :module: target.annotations',
'',
' docstring',
'',
'',
' .. py:attribute:: Foo.attr',
' :module: target.annotations',
' :type: int',
'',
' docstring',
'',
'',
'.. py:function:: mult(x: int, y: int) -> int',
' mult(x: float, y: float) -> float',
' :module: target.annotations',
@ -712,6 +725,13 @@ def test_autodoc_type_aliases(app):
'',
' docstring',
'',
'',
'.. py:data:: variable',
' :module: target.annotations',
' :type: int',
'',
' docstring',
'',
]
# define aliases
@ -722,6 +742,19 @@ def test_autodoc_type_aliases(app):
'.. py:module:: target.annotations',
'',
'',
'.. py:class:: Foo()',
' :module: target.annotations',
'',
' docstring',
'',
'',
' .. py:attribute:: Foo.attr',
' :module: target.annotations',
' :type: myint',
'',
' docstring',
'',
'',
'.. py:function:: mult(x: myint, y: myint) -> myint',
' mult(x: float, y: float) -> float',
' :module: target.annotations',
@ -734,6 +767,13 @@ def test_autodoc_type_aliases(app):
'',
' docstring',
'',
'',
'.. py:data:: variable',
' :module: target.annotations',
' :type: myint',
'',
' docstring',
'',
]