diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-12-17 00:46:49 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-12-17 01:07:54 +0900 |
commit | 55c110f60965ea6f0ea32d129b62413f1f84b3f4 (patch) | |
tree | e3065e10b0db4b3749096b6e59433ad8e1565559 /tests | |
parent | 36e684bf83d14e587f0bf48eb0980f41ab66733e (diff) | |
download | sphinx-git-55c110f60965ea6f0ea32d129b62413f1f84b3f4.tar.gz |
Fix #8541: autodoc_type_aliases doesn't work for the instance attrs
So far, autodoc obtains type annotations of instance attributes by
ModuleAnalyzer directly. As a result, autodoc_type_aliases are ignored
for these variables.
This goes to merge type annotations from the class itself and
ModuleAnalyzer's, and get type annotations using `typing.get_type_hints()`
to apply autodoc_type_aliases.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/roots/test-ext-autodoc/target/annotations.py | 8 | ||||
-rw-r--r-- | tests/test_ext_autodoc.py | 16 | ||||
-rw-r--r-- | tests/test_ext_autodoc_configs.py | 34 |
3 files changed, 55 insertions, 3 deletions
diff --git a/tests/roots/test-ext-autodoc/target/annotations.py b/tests/roots/test-ext-autodoc/target/annotations.py index e9ff2f604..ef600e2af 100644 --- a/tests/roots/test-ext-autodoc/target/annotations.py +++ b/tests/roots/test-ext-autodoc/target/annotations.py @@ -7,6 +7,9 @@ myint = int #: docstring variable: myint +#: docstring +variable2 = None # type: myint + def sum(x: myint, y: myint) -> myint: """docstring""" @@ -32,4 +35,7 @@ class Foo: """docstring""" #: docstring - attr: myint + attr1: myint + + def __init__(self): + self.attr2: myint = None #: docstring diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index 52f69dd2e..a81a73b61 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -1675,9 +1675,25 @@ def test_autodoc_typed_inherited_instance_variables(app): '', ' .. py:attribute:: Derived.attr3', ' :module: target.typed_vars', + ' :type: int', ' :value: 0', '', '', + ' .. py:attribute:: Derived.attr4', + ' :module: target.typed_vars', + ' :type: int', + '', + '', + ' .. py:attribute:: Derived.attr5', + ' :module: target.typed_vars', + ' :type: int', + '', + '', + ' .. py:attribute:: Derived.attr6', + ' :module: target.typed_vars', + ' :type: int', + '', + '', ' .. py:attribute:: Derived.attr7', ' :module: target.typed_vars', ' :type: int', diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py index d76ed25e3..ac0a2c11c 100644 --- a/tests/test_ext_autodoc_configs.py +++ b/tests/test_ext_autodoc_configs.py @@ -707,7 +707,14 @@ def test_autodoc_type_aliases(app): ' docstring', '', '', - ' .. py:attribute:: Foo.attr', + ' .. py:attribute:: Foo.attr1', + ' :module: target.annotations', + ' :type: int', + '', + ' docstring', + '', + '', + ' .. py:attribute:: Foo.attr2', ' :module: target.annotations', ' :type: int', '', @@ -733,6 +740,14 @@ def test_autodoc_type_aliases(app): '', ' docstring', '', + '', + '.. py:data:: variable2', + ' :module: target.annotations', + ' :type: int', + ' :value: None', + '', + ' docstring', + '', ] # define aliases @@ -749,7 +764,14 @@ def test_autodoc_type_aliases(app): ' docstring', '', '', - ' .. py:attribute:: Foo.attr', + ' .. py:attribute:: Foo.attr1', + ' :module: target.annotations', + ' :type: myint', + '', + ' docstring', + '', + '', + ' .. py:attribute:: Foo.attr2', ' :module: target.annotations', ' :type: myint', '', @@ -775,6 +797,14 @@ def test_autodoc_type_aliases(app): '', ' docstring', '', + '', + '.. py:data:: variable2', + ' :module: target.annotations', + ' :type: myint', + ' :value: None', + '', + ' docstring', + '', ] |