Skip to content

Commit

Permalink
Set the docstring attribute of class members. Fixes sphinx-doc#8180.
Browse files Browse the repository at this point in the history
Change ext.autodoc.importer.get_class_members to set
ObjectMember.docstring the docstring found by the source code
analyzer.
  • Loading branch information
Anselm Kruis committed May 13, 2022
1 parent e6f2410 commit 68d6513
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sphinx/ext/autodoc/importer.py
Expand Up @@ -280,12 +280,19 @@ def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable
members[name] = ObjectMember(name, INSTANCEATTR, class_=cls,
docstring=docstring)

# append instance attributes (cf. self.attr1) if analyzer knows
# append or complete instance attributes (cf. self.attr1) if analyzer knows
if analyzer:
for (ns, name), docstring in analyzer.attr_docs.items():
if ns == qualname and name not in members:
# otherwise unknown instance attribute
members[name] = ObjectMember(name, INSTANCEATTR, class_=cls,
docstring='\n'.join(docstring))
elif (ns == qualname and docstring and
isinstance(members[name], ObjectMember) and
not members[name].docstring):
# attribute is already known, because dir(subject) enumerates it.
# But it has no docstring yet
members[name].docstring = '\n'.join(docstring)
except AttributeError:
pass

Expand Down

0 comments on commit 68d6513

Please sign in to comment.