Skip to content

Commit

Permalink
Merge pull request #8085 from tk0miya/8084_KeyError_for_broken_class
Browse files Browse the repository at this point in the history
Fix #8084: autodoc: KeyError is raised on documenting a broken attribute
  • Loading branch information
tk0miya committed Aug 10, 2020
2 parents e4a55cb + 24f690c commit 38b868c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -38,6 +38,8 @@ Bugs fixed
----------

* #8074: napoleon: Crashes during processing C-ext module
* #8084: autodoc: KeyError is raised on documenting an attribute of the broken
class

Testing
--------
Expand Down
6 changes: 6 additions & 0 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1610,6 +1610,9 @@ def add_directive_header(self, sig: str) -> None:
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]))
Expand Down Expand Up @@ -1980,6 +1983,9 @@ def add_directive_header(self, sig: str) -> None:
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]))
Expand Down

0 comments on commit 38b868c

Please sign in to comment.