From 6c3db6d65a3912fd9b21497fdcc63c9630132912 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 13 Jun 2020 19:53:08 +0900 Subject: [PATCH] Fix #7805: autodoc: an object which descriptors returns is documented --- CHANGES | 1 + sphinx/ext/autodoc/__init__.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGES b/CHANGES index 88059348ee6..a5aa1ed312e 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ Bugs fixed * #7808: autodoc: Warnings raised on variable and attribute type annotations * #7802: autodoc: EOFError is raised on parallel build * #7821: autodoc: TypeError is raised for overloaded C-ext function +* #7805: autodoc: an object which descriptors returns is unexpectedly documented * #7812: autosummary: generates broken stub files if the target code contains an attribute and module that are same name * #7808: napoleon: Warnings raised on variable and attribute type annotations diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 754c4fddaf2..ab75aaf5a9e 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1929,6 +1929,17 @@ def add_directive_header(self, sig: str) -> None: else: self.add_line(' :annotation: %s' % self.options.annotation, sourcename) + def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]: + try: + # Disable `autodoc_inherit_docstring` temporarily to avoid to obtain + # a docstring from the value which descriptor returns unexpectedly. + # ref: https://github.com/sphinx-doc/sphinx/issues/7805 + orig = self.env.config.autodoc_inherit_docstrings + self.env.config.autodoc_inherit_docstrings = False # type: ignore + return super().get_doc(encoding, ignore) + finally: + self.env.config.autodoc_inherit_docstrings = orig # type: ignore + def add_content(self, more_content: Any, no_docstring: bool = False) -> None: if not self._datadescriptor: # if it's not a data descriptor, its docstring is very probably the