summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-14 19:58:40 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-14 19:58:40 +0900
commit5ade6b72196edd44d043888fc7847f36577d694c (patch)
tree101399540f1100b13e09898e75ab7f0771a2aa97
parent8412347f5dc129b42e4dd05d7f8921a77fe90918 (diff)
parentf861b4cd1a5d5f1a100dca709ea72a7e4c007bd7 (diff)
downloadsphinx-git-5ade6b72196edd44d043888fc7847f36577d694c.tar.gz
Merge branch '3.x' into master
-rw-r--r--CHANGES18
-rw-r--r--sphinx/ext/autodoc/__init__.py6
-rw-r--r--tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py8
-rw-r--r--tests/test_ext_autodoc.py22
4 files changed, 50 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index e6705fa3e..03783b736 100644
--- a/CHANGES
+++ b/CHANGES
@@ -67,7 +67,7 @@ Bugs fixed
Testing
--------
-Release 3.2.1 (in development)
+Release 3.2.2 (in development)
==============================
Dependencies
@@ -82,6 +82,18 @@ Deprecated
Features added
--------------
+Bugs fixed
+----------
+
+Testing
+--------
+
+Release 3.2.1 (released Aug 14, 2020)
+=====================================
+
+Features added
+--------------
+
* #8095: napoleon: Add :confval:`napoleon_preprocess_types` to enable the type
preprocessor for numpy style docstrings
* #8114: C and C++, parse function attributes after parameters and qualifiers.
@@ -96,11 +108,9 @@ Bugs fixed
class
* #8091: autodoc: AttributeError is raised on documenting an attribute on Python
3.5.2
+* #8099: autodoc: NameError is raised when target code uses ``TYPE_CHECKING``
* C++, fix parsing of template template paramters, broken by the fix of #7944
-Testing
---------
-
Release 3.2.0 (released Aug 08, 2020)
=====================================
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index dbeb2170e..4d01da07e 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -1589,6 +1589,9 @@ class DataDocumenter(ModuleLevelDocumenter):
# obtain annotation for this data
try:
annotations = get_type_hints(self.parent)
+ except NameError:
+ # Failed to evaluate ForwardRef (maybe TYPE_CHECKING)
+ annotations = safe_getattr(self.parent, '__annotations__', {})
except TypeError:
annotations = {}
except KeyError:
@@ -1965,6 +1968,9 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
# obtain type annotation for this attribute
try:
annotations = get_type_hints(self.parent)
+ except NameError:
+ # Failed to evaluate ForwardRef (maybe TYPE_CHECKING)
+ annotations = safe_getattr(self.parent, '__annotations__', {})
except TypeError:
annotations = {}
except KeyError:
diff --git a/tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py b/tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py
new file mode 100644
index 000000000..aa7eb99a6
--- /dev/null
+++ b/tests/roots/test-ext-autodoc/target/TYPE_CHECKING.py
@@ -0,0 +1,8 @@
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from io import StringIO
+
+
+class Foo:
+ attr1: "StringIO"
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,