From a7daa19a939545f615158012312129b8020b626d Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 27 Jul 2021 23:55:26 +0900 Subject: [PATCH] Fix #9479: autodoc: Emit a warning if target is a mocked object --- CHANGES | 1 + sphinx/ext/autodoc/__init__.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index 29d6e98f29e..417069ddc2f 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ Features added -------------- * #9445: autodoc: Support class properties +* #9479: autodoc: Emit a warning if target is a mocked object * #9445: py domain: ``:py:property:`` directive supports ``:classmethod:`` option to describe the class property diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 97815c09eb9..bbbeae78a1a 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -913,6 +913,10 @@ def generate(self, more_content: Optional[StringList] = None, real_modname: str if not self.import_object(): return + if ismock(self.object): + logger.warning(__('A mocked object is detected: %r'), + self.name, type='autodoc') + # If there is no real module defined, figure out which to use. # The real module is used in the module analyzer to look up the module # where the attribute documentation would actually be found in.