Skip to content

Commit

Permalink
Fix sphinx-doc#8164: autosummary_mock_imports causes slow down builds
Browse files Browse the repository at this point in the history
The mock objects set up via `autosummary_mock_imports` causes slow down
of autosummary stub generation because AttributeDocumenter falls into
infinite recursion call to unwrap decorators of mocked objects.

To avoid the trouble, this blocks unwrapping decorators of mocked
objects.
  • Loading branch information
tk0miya committed Nov 11, 2020
1 parent de2d2cc commit 448bd97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -19,6 +19,7 @@ Bugs fixed
* #8372: autodoc: autoclass directive became slower than Sphinx-3.2
* #7727: autosummary: raise PycodeError when documenting python package
without __init__.py
* #8164: autosummary: autosummary_mock_imports causes slow down builds
* #8364: C, properly initialize attributes in empty symbols.
* #8399: i18n: Put system locale path after the paths specified by configuration

Expand Down
6 changes: 5 additions & 1 deletion sphinx/util/inspect.py
Expand Up @@ -122,7 +122,11 @@ def getargspec(func: Callable) -> Any:
def unwrap(obj: Any) -> Any:
"""Get an original object from wrapped object (wrapped functions)."""
try:
return inspect.unwrap(obj)
if hasattr(obj, '__sphinx_mock__'):
# Skip unwrapping mock object to avoid RecursionError
return obj
else:
return inspect.unwrap(obj)
except ValueError:
# might be a mock object
return obj
Expand Down

0 comments on commit 448bd97

Please sign in to comment.