diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-08-09 23:40:29 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-08-09 23:43:01 +0900 |
commit | f7431b927cab199682a44b11849f347f692f6eca (patch) | |
tree | 8d8b803fbf26c7b2383598f6c46f1c803b322a64 | |
parent | 40bdeb2c1603abc1d7b07b3e617904f8c3fbb1fe (diff) | |
download | sphinx-git-f7431b927cab199682a44b11849f347f692f6eca.tar.gz |
Fix #8084: autodoc: KeyError is raised on documenting a broken attribute
``typing.get_type_hints()`` raises KeyError when a class having invalid
__module__ was given. This handles the exception not to crash on build
documents.
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | sphinx/ext/autodoc/__init__.py | 6 |
2 files changed, 9 insertions, 0 deletions
@@ -37,6 +37,9 @@ Features added Bugs fixed ---------- +* #8084: autodoc: KeyError is raised on documenting an attribute of the broken + class + Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 0a64b56e2..47f6bcb25 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1610,6 +1610,9 @@ class DataDocumenter(ModuleLevelDocumenter): annotations = get_type_hints(self.parent) except TypeError: annotations = {} + except KeyError: + # a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084) + annotations = {} if self.objpath[-1] in annotations: objrepr = stringify_typehint(annotations.get(self.objpath[-1])) @@ -1980,6 +1983,9 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter): annotations = get_type_hints(self.parent) except TypeError: annotations = {} + except KeyError: + # a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084) + annotations = {} if self.objpath[-1] in annotations: objrepr = stringify_typehint(annotations.get(self.objpath[-1])) |