Skip to content

Commit

Permalink
Merge pull request #9668 from tk0miya/9655_mocked_object_having_docco…
Browse files Browse the repository at this point in the history
…mment

Fix #9655: autodoc: mocked object having doc comment is warned unexpectedly
  • Loading branch information
tk0miya committed Sep 25, 2021
2 parents de59a72 + bdc2112 commit 5fb51fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -23,6 +23,7 @@ Bugs fixed
* #9630: autodoc: Failed to build cross references if :confval:`primary_domain`
is not 'py'
* #9644: autodoc: Crashed on getting source info from problematic object
* #9655: autodoc: mocked object having doc comment is warned unexpectedly
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
is not 'py'
* #9670: html: Fix download file with special characters
Expand Down
9 changes: 5 additions & 4 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -913,10 +913,6 @@ 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.
Expand Down Expand Up @@ -949,6 +945,11 @@ def generate(self, more_content: Optional[StringList] = None, real_modname: str
except PycodeError:
pass

docstrings: List[str] = sum(self.get_doc() or [], [])
if ismock(self.object) and not docstrings:
logger.warning(__('A mocked object is detected: %r'),
self.name, type='autodoc')

# check __module__ of object (for members not given explicitly)
if check_module:
if not self.check_module():
Expand Down

0 comments on commit 5fb51fb

Please sign in to comment.