Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>2022-06-08 17:45:27 +0300
committerAdam Turner <9087854+AA-Turner@users.noreply.github.com>2022-06-08 17:50:56 +0300
commit3956cf2249d27ed63e8381c07dfde36f6c96f78f (patch)
tree7a3d59a04f9dc6d9e0a12754656484e571d6833a
parent60775ec4c4ea08509eee4b564cbf90f316021aff (diff)
Fix documenting inherited attributes
-rw-r--r--sphinx/ext/autodoc/__init__.py3
-rw-r--r--sphinx/ext/autodoc/importer.py9
2 files changed, 9 insertions, 3 deletions
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index e16ab8ce5..642e0cfd8 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -1670,7 +1670,8 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
self.add_line(' ' + _('Bases: %s') % ', '.join(base_classes), sourcename)
def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]:
- members = get_class_members(self.object, self.objpath, self.get_attr)
+ members = get_class_members(self.object, self.objpath, self.get_attr,
+ self.config.autodoc_inherit_docstrings)
if not want_all:
if not self.options.members:
return False, [] # type: ignore
diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py
index 85c1e81be..d392ae75d 100644
--- a/sphinx/ext/autodoc/importer.py
+++ b/sphinx/ext/autodoc/importer.py
@@ -205,8 +205,8 @@ def get_object_members(subject: Any, objpath: List[str], attrgetter: Callable,
return members
-def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable
- ) -> Dict[str, "ObjectMember"]:
+def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable,
+ inherit_docstrings: bool = True) -> Dict[str, "ObjectMember"]:
"""Get members and attributes of target class."""
from sphinx.ext.autodoc import INSTANCEATTR, ObjectMember
@@ -290,6 +290,11 @@ def get_class_members(subject: Any, objpath: List[str], attrgetter: Callable
elif (ns == qualname and docstring and
isinstance(members[name], ObjectMember) and
not members[name].docstring):
+ if cls != subject and not inherit_docstrings:
+ # If we are in the MRO of the class and not the class itself,
+ # and we do not want to inherit docstrings, then skip setting
+ # the docstring below
+ continue
# attribute is already known, because dir(subject) enumerates it.
# But it has no docstring yet
members[name].docstring = '\n'.join(docstring)