diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-31 13:21:15 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-02-01 15:06:07 +0300 |
commit | 6d8c9183fa6ce047236f673ae9676112bae58fe0 (patch) | |
tree | 6f94c220da731250898e7cc894b2a7063b026ed0 /sphinx/ext | |
parent | 7ca279e33aebb60168d35e6be4ed059f4a68f2c1 (diff) |
Fix #8800: autodoc: Uninitialized attributes in superclass are recognized as undocumented
Unintentionally, uninitialized attributes defined at superclasses are
recognized as undocumented in the filtering step. Therefore, they are
filtered if `:undoc-members:` option given.
Diffstat (limited to 'sphinx/ext')
-rw-r--r-- | sphinx/ext/autodoc/importer.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index 477aae247..b792b1a5f 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -294,24 +294,35 @@ def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable try: for cls in getmro(subject): + try: + modname = safe_getattr(cls, '__module__') + qualname = safe_getattr(cls, '__qualname__') + analyzer = ModuleAnalyzer.for_module(modname) + analyzer.analyze() + except AttributeError: + qualname = None + analyzer = None + except PycodeError: + analyzer = None + # annotation only member (ex. attr: int) for name in getannotations(cls): name = unmangle(cls, name) if name and name not in members: - members[name] = ObjectMember(name, INSTANCEATTR, class_=cls) + if analyzer and (qualname, name) in analyzer.attr_docs: + docstring = '\n'.join(analyzer.attr_docs[qualname, name]) + else: + docstring = None + + members[name] = ObjectMember(name, INSTANCEATTR, class_=cls, + docstring=docstring) # append instance attributes (cf. self.attr1) if analyzer knows - try: - modname = safe_getattr(cls, '__module__') - qualname = safe_getattr(cls, '__qualname__') - analyzer = ModuleAnalyzer.for_module(modname) - analyzer.analyze() + if analyzer: for (ns, name), docstring in analyzer.attr_docs.items(): if ns == qualname and name not in members: members[name] = ObjectMember(name, INSTANCEATTR, class_=cls, docstring='\n'.join(docstring)) - except (AttributeError, PycodeError): - pass except AttributeError: pass |