Fix #4606: autodoc: the location of the warning is incorrect for inherited method

This commit is contained in:
Takeshi KOMIYA
2020-11-04 01:34:59 +09:00
parent c028fb7a40
commit 2da6de6721
2 changed files with 13 additions and 2 deletions

View File

@@ -20,6 +20,8 @@ Features added
Bugs fixed Bugs fixed
---------- ----------
* #4606: autodoc: the location of the warning is incorrect for inherited method
Testing Testing
-------- --------

View File

@@ -543,9 +543,18 @@ class Documenter:
yield from docstringlines yield from docstringlines
def get_sourcename(self) -> str: def get_sourcename(self) -> str:
if (getattr(self.object, '__module__', None) and
getattr(self.object, '__qualname__', None)):
# Get the correct location of docstring from self.object
# to support inherited methods
fullname = '%s.%s' % (self.object.__module__, self.object.__qualname__)
else:
fullname = self.fullname
if self.analyzer: if self.analyzer:
return '%s:docstring of %s' % (self.analyzer.srcname, self.fullname) return '%s:docstring of %s' % (self.analyzer.srcname, fullname)
return 'docstring of %s' % self.fullname else:
return 'docstring of %s' % fullname
def add_content(self, more_content: Any, no_docstring: bool = False) -> None: def add_content(self, more_content: Any, no_docstring: bool = False) -> None:
"""Add content from docstrings, attribute documentation and user.""" """Add content from docstrings, attribute documentation and user."""