From 2da6de67219ed86acf0e0835b5330ee3269b5011 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 4 Nov 2020 01:34:59 +0900 Subject: [PATCH] Fix #4606: autodoc: the location of the warning is incorrect for inherited method --- CHANGES | 2 ++ sphinx/ext/autodoc/__init__.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 99e5cdaf9be..8ed105f9de4 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,8 @@ Features added Bugs fixed ---------- +* #4606: autodoc: the location of the warning is incorrect for inherited method + Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 7343d41b6a9..968b483b753 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -543,9 +543,18 @@ def process_doc(self, docstrings: List[List[str]]) -> Iterator[str]: yield from docstringlines 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: - return '%s:docstring of %s' % (self.analyzer.srcname, self.fullname) - return 'docstring of %s' % self.fullname + return '%s:docstring of %s' % (self.analyzer.srcname, fullname) + else: + return 'docstring of %s' % fullname def add_content(self, more_content: Any, no_docstring: bool = False) -> None: """Add content from docstrings, attribute documentation and user."""