summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-11-16 02:11:15 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-11-16 02:11:15 +0900
commit44fbe9da7b13742d4ea14c15b5a3cd5fdeeade53 (patch)
tree735154af40580783b2dc98eb45cd5b20dcda822d
parent5d8d6275a54f2c5fb72b82383b5712c22d337634 (diff)
downloadsphinx-git-44fbe9da7b13742d4ea14c15b5a3cd5fdeeade53.tar.gz
Fix #8434: autodoc_type_aliases does not effect to variables
-rw-r--r--CHANGES2
-rw-r--r--sphinx/ext/autodoc/__init__.py6
-rw-r--r--tests/roots/test-ext-autodoc/target/annotations.py10
-rw-r--r--tests/test_ext_autodoc_configs.py40
4 files changed, 56 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index a55a43687..6dd7a7420 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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
--------
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 171a3e7b0..a79e540eb 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -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__', {})
diff --git a/tests/roots/test-ext-autodoc/target/annotations.py b/tests/roots/test-ext-autodoc/target/annotations.py
index 691176b08..e9ff2f604 100644
--- a/tests/roots/test-ext-autodoc/target/annotations.py
+++ b/tests/roots/test-ext-autodoc/target/annotations.py
@@ -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
diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py
index 3d1005ac0..4dff7c3db 100644
--- a/tests/test_ext_autodoc_configs.py
+++ b/tests/test_ext_autodoc_configs.py
@@ -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',
+ '',
]