mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
commit
dd1615c59d
@ -2162,14 +2162,19 @@ class UninitializedInstanceAttributeMixin(DataDocumenterMixinBase):
|
||||
|
||||
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
|
||||
|
||||
|
@ -31,4 +31,4 @@ class Derived(Class):
|
||||
attr7: int
|
||||
|
||||
|
||||
Alias = Class
|
||||
Alias = Derived
|
||||
|
@ -1570,7 +1570,7 @@ def test_autodoc_typed_instance_variables(app):
|
||||
'.. py:attribute:: Alias',
|
||||
' :module: target.typed_vars',
|
||||
'',
|
||||
' alias of :class:`target.typed_vars.Class`',
|
||||
' alias of :class:`target.typed_vars.Derived`',
|
||||
'',
|
||||
'.. py:class:: Class()',
|
||||
' :module: target.typed_vars',
|
||||
@ -1689,16 +1689,22 @@ def test_autodoc_typed_inherited_instance_variables(app):
|
||||
' :module: target.typed_vars',
|
||||
' :type: int',
|
||||
'',
|
||||
' attr4',
|
||||
'',
|
||||
'',
|
||||
' .. py:attribute:: Derived.attr5',
|
||||
' :module: target.typed_vars',
|
||||
' :type: int',
|
||||
'',
|
||||
' attr5',
|
||||
'',
|
||||
'',
|
||||
' .. py:attribute:: Derived.attr6',
|
||||
' :module: target.typed_vars',
|
||||
' :type: int',
|
||||
'',
|
||||
' attr6',
|
||||
'',
|
||||
'',
|
||||
' .. py:attribute:: Derived.attr7',
|
||||
' :module: target.typed_vars',
|
||||
|
Loading…
Reference in New Issue
Block a user