Skip to content

Commit

Permalink
Fix sphinx-doc#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 18, 2020
1 parent 50d2d28 commit 7a93161
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -21,6 +21,7 @@ Bugs fixed

* #7461: py domain: fails with IndexError for empty tuple in type annotation
* #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.

Testing
Expand Down
3 changes: 3 additions & 0 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -578,6 +578,9 @@ def is_filtered_inherited_member(name: str) -> bool:
isprivate = membername.startswith('_')

keep = False
if getattr(member, '__sphinx_mock__', False):
# mocked module or object
keep = False
if want_all and membername.startswith('__') and \
membername.endswith('__') and len(membername) > 4:
# special __methods__
Expand Down
5 changes: 4 additions & 1 deletion 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 @@ -69,7 +70,8 @@ def __repr__(self) -> str:

def _make_subclass(name: str, module: str, superclass: Any = _MockObject,
attributes: Any = None) -> Any:
attrs = {'__module__': module, '__display_name__': module + '.' + name}
attrs = {'__module__': module,
'__display_name__': module + '.' + name}
attrs.update(attributes or {})

return type(name, (superclass,), attrs)
Expand All @@ -78,6 +80,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 7a93161

Please sign in to comment.