Skip to content

Commit

Permalink
Fix #8534: autoattribute failed to document a commented attribute in …
Browse files Browse the repository at this point in the history
…alias dervied class
  • Loading branch information
tk0miya committed Dec 16, 2020
1 parent 55c110f commit 966db73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,14 +2152,19 @@ def __init__(self):

def get_attribute_comment(self, parent: Any) -> Optional[List[str]]:
try:
analyzer = ModuleAnalyzer.for_module(self.modname)
analyzer.analyze()
for cls in inspect.getmro(parent):
try:
module = safe_getattr(cls, '__module__')
qualname = safe_getattr(cls, '__qualname__')

qualname = safe_getattr(parent, '__qualname__', None)
if qualname and self.objpath:
key = (qualname, self.objpath[-1])
if key in analyzer.attr_docs:
return list(analyzer.attr_docs[key])
analyzer = ModuleAnalyzer.for_module(module)
analyzer.analyze()
if qualname and self.objpath:
key = (qualname, self.objpath[-1])
if key in analyzer.attr_docs:
return list(analyzer.attr_docs[key])
except (AttributeError, PycodeError):
pass
except (AttributeError, PycodeError):
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-autodoc/target/typed_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class Derived(Class):
attr7: int


Alias = Class
Alias = Derived

0 comments on commit 966db73

Please sign in to comment.