Skip to content

Commit

Permalink
Fix #7479: autodoc: Sphinx builds has been slower since 3.0.0
Browse files Browse the repository at this point in the history
Call ``inspect.unwrap()`` for Mocked objects and modules causes
deep recurrsion calls. As a result, it causes slow builds.  This
skips to try documenting mocked objects on filtering members.
  • Loading branch information
tk0miya committed Apr 19, 2020
1 parent 61f00bf commit 841f1c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -22,6 +22,7 @@ Bugs fixed
* #7461: py domain: fails with IndexError for empty tuple in type annotation
* #7418: std domain: :rst:role:`term` role could not match case-insensitively
* #7461: autodoc: empty tuple in type annotation is not shown correctly
* #7479: autodoc: Sphinx builds has been slower since 3.0.0 on mocking
* C++, fix spacing issue in east-const declarations.
* #7414: LaTeX: Xindy language options were incorrect

Expand Down
5 changes: 4 additions & 1 deletion sphinx/ext/autodoc/__init__.py
Expand Up @@ -578,7 +578,10 @@ def is_filtered_inherited_member(name: str) -> bool:
isprivate = membername.startswith('_')

keep = False
if want_all and membername.startswith('__') and \
if getattr(member, '__sphinx_mock__', False):
# mocked module or object
keep = False
elif want_all and membername.startswith('__') and \
membername.endswith('__') and len(membername) > 4:
# special __methods__
if self.options.special_members is ALL:
Expand Down
2 changes: 2 additions & 0 deletions sphinx/ext/autodoc/mock.py
Expand Up @@ -25,6 +25,7 @@ class _MockObject:
"""Used by autodoc_mock_imports."""

__display_name__ = '_MockObject'
__sphinx_mock__ = True

def __new__(cls, *args: Any, **kwargs: Any) -> Any:
if len(args) == 3 and isinstance(args[1], tuple):
Expand Down Expand Up @@ -78,6 +79,7 @@ def _make_subclass(name: str, module: str, superclass: Any = _MockObject,
class _MockModule(ModuleType):
"""Used by autodoc_mock_imports."""
__file__ = os.devnull
__sphinx_mock__ = True

def __init__(self, name: str) -> None:
super().__init__(name)
Expand Down

0 comments on commit 841f1c7

Please sign in to comment.