diff --git a/CHANGES b/CHANGES index 0926737463..d0e4e6316c 100644 --- a/CHANGES +++ b/CHANGES @@ -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 -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 0a64b56e2b..47f6bcb250 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -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])) @@ -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]))