mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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.
This commit is contained in:
parent
40bdeb2c16
commit
f7431b927c
3
CHANGES
3
CHANGES
@ -37,6 +37,9 @@ Features added
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
* #8084: autodoc: KeyError is raised on documenting an attribute of the broken
|
||||
class
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
||||
|
@ -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]))
|
||||
|
Loading…
Reference in New Issue
Block a user