diff --git a/CHANGES b/CHANGES index 5f645efa843..3724c65cab3 100644 --- a/CHANGES +++ b/CHANGES @@ -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 0a64b56e2b9..47f6bcb2506 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]))