summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/ext/autodoc/__init__.py')
-rw-r--r--sphinx/ext/autodoc/__init__.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 7578ebab4..b481cf254 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -2096,18 +2096,36 @@ class NonDataDescriptorMixin(DataDocumenterMixinBase):
and :value: header will be suppressed unexpectedly.
"""
+ def import_object(self, raiseerror: bool = False) -> bool:
+ ret = super().import_object(raiseerror) # type: ignore
+ if ret and not inspect.isattributedescriptor(self.object):
+ self.non_data_descriptor = True
+ else:
+ self.non_data_descriptor = False
+
+ return ret
+
def should_suppress_value_header(self) -> bool:
- return (inspect.isattributedescriptor(self.object) or
+ return (not getattr(self, 'non_data_descriptor', False) or
super().should_suppress_directive_header())
def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]:
- if not inspect.isattributedescriptor(self.object):
+ if getattr(self, 'non_data_descriptor', False):
# the docstring of non datadescriptor is very probably the wrong thing
# to display
return []
else:
return super().get_doc(encoding, ignore) # type: ignore
+ def add_content(self, more_content: Optional[StringList], no_docstring: bool = False
+ ) -> None:
+ if getattr(self, 'non_data_descriptor', False):
+ # the docstring of non datadescriptor is very probably the wrong thing
+ # to display
+ no_docstring = True
+
+ super().add_content(more_content, no_docstring=no_docstring) # type: ignore
+
class SlotsMixin(DataDocumenterMixinBase):
"""