Merge pull request #8543 from tk0miya/8534_autoattribute_alias_derived

Fix #8534: autoattribute failed to document a commented attribute in alias dervied class
This commit is contained in:
Takeshi KOMIYA 2020-12-17 22:35:35 +09:00 committed by GitHub
commit dd1615c59d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -2162,16 +2162,21 @@ class UninitializedInstanceAttributeMixin(DataDocumenterMixinBase):
def get_attribute_comment(self, parent: Any) -> Optional[List[str]]: def get_attribute_comment(self, parent: Any) -> Optional[List[str]]:
try: try:
analyzer = ModuleAnalyzer.for_module(self.modname) for cls in inspect.getmro(parent):
analyzer.analyze() try:
module = safe_getattr(cls, '__module__')
qualname = safe_getattr(cls, '__qualname__')
qualname = safe_getattr(parent, '__qualname__', None) analyzer = ModuleAnalyzer.for_module(module)
analyzer.analyze()
if qualname and self.objpath: if qualname and self.objpath:
key = (qualname, self.objpath[-1]) key = (qualname, self.objpath[-1])
if key in analyzer.attr_docs: if key in analyzer.attr_docs:
return list(analyzer.attr_docs[key]) return list(analyzer.attr_docs[key])
except (AttributeError, PycodeError): except (AttributeError, PycodeError):
pass pass
except (AttributeError, PycodeError):
pass
return None return None

View File

@ -31,4 +31,4 @@ class Derived(Class):
attr7: int attr7: int
Alias = Class Alias = Derived

View File

@ -1570,7 +1570,7 @@ def test_autodoc_typed_instance_variables(app):
'.. py:attribute:: Alias', '.. py:attribute:: Alias',
' :module: target.typed_vars', ' :module: target.typed_vars',
'', '',
' alias of :class:`target.typed_vars.Class`', ' alias of :class:`target.typed_vars.Derived`',
'', '',
'.. py:class:: Class()', '.. py:class:: Class()',
' :module: target.typed_vars', ' :module: target.typed_vars',
@ -1689,16 +1689,22 @@ def test_autodoc_typed_inherited_instance_variables(app):
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: int', ' :type: int',
'', '',
' attr4',
'',
'', '',
' .. py:attribute:: Derived.attr5', ' .. py:attribute:: Derived.attr5',
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: int', ' :type: int',
'', '',
' attr5',
'',
'', '',
' .. py:attribute:: Derived.attr6', ' .. py:attribute:: Derived.attr6',
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: int', ' :type: int',
'', '',
' attr6',
'',
'', '',
' .. py:attribute:: Derived.attr7', ' .. py:attribute:: Derived.attr7',
' :module: target.typed_vars', ' :module: target.typed_vars',