Skip to content

Commit 3956cf2

Browse files
committed
Fix documenting inherited attributes
1 parent 60775ec commit 3956cf2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

sphinx/ext/autodoc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,8 @@ def add_directive_header(self, sig: str) -> None:
16701670
self.add_line(' ' + _('Bases: %s') % ', '.join(base_classes), sourcename)
16711671

16721672
def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]:
1673-
members = get_class_members(self.object, self.objpath, self.get_attr)
1673+
members = get_class_members(self.object, self.objpath, self.get_attr,
1674+
self.config.autodoc_inherit_docstrings)
16741675
if not want_all:
16751676
if not self.options.members:
16761677
return False, [] # type: ignore

sphinx/ext/autodoc/importer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ def get_object_members(subject: Any, objpath: List[str], attrgetter: Callable,
205205
return members
206206

207207

208-
def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable
209-
) -> Dict[str, "ObjectMember"]:
208+
def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable,
209+
inherit_docstrings: bool = True) -> Dict[str, "ObjectMember"]:
210210
"""Get members and attributes of target class."""
211211
from sphinx.ext.autodoc import INSTANCEATTR, ObjectMember
212212

@@ -290,6 +290,11 @@ def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable
290290
elif (ns == qualname and docstring and
291291
isinstance(members[name], ObjectMember) and
292292
not members[name].docstring):
293+
if cls != subject and not inherit_docstrings:
294+
# If we are in the MRO of the class and not the class itself,
295+
# and we do not want to inherit docstrings, then skip setting
296+
# the docstring below
297+
continue
293298
# attribute is already known, because dir(subject) enumerates it.
294299
# But it has no docstring yet
295300
members[name].docstring = '\n'.join(docstring)

0 commit comments

Comments
 (0)