diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-08-13 00:05:27 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-08-13 22:57:12 +0900 |
| commit | 611fff975e9c1b3972fd9e2dfd7a96d3d8d8cdb7 (patch) | |
| tree | 179edce38c8a346e9cef5c241554e56b6b547808 /tests/test_ext_autodoc.py | |
| parent | 99e36398fcb5fd4e07dd0dcad1c36afaa7e75800 (diff) | |
| download | sphinx-git-611fff975e9c1b3972fd9e2dfd7a96d3d8d8cdb7.tar.gz | |
Fix #8099: autodoc: NameError is raised when script uses TYPE_CHECKING
`typing.get_type_hints()` raises NameError when the target object
contains unresolavable type annotation (ex. TYPE_CHECKING). This
handles the exception and use unresolved annotations for type hints.
Diffstat (limited to 'tests/test_ext_autodoc.py')
| -rw-r--r-- | tests/test_ext_autodoc.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index 15e1f3539..90a2ec95a 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -1740,6 +1740,28 @@ def test_autodoc_Annotated(app): ] +@pytest.mark.skipif(sys.version_info < (3, 6), reason='py36+ is required.') +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_autodoc_TYPE_CHECKING(app): + options = {"members": None, + "undoc-members": None} + actual = do_autodoc(app, 'module', 'target.TYPE_CHECKING', options) + assert list(actual) == [ + '', + '.. py:module:: target.TYPE_CHECKING', + '', + '', + '.. py:class:: Foo()', + ' :module: target.TYPE_CHECKING', + '', + '', + ' .. py:attribute:: Foo.attr1', + ' :module: target.TYPE_CHECKING', + ' :type: StringIO', + '', + ] + + @pytest.mark.sphinx('html', testroot='pycode-egg') def test_autodoc_for_egged_code(app): options = {"members": None, |
