From 953a5ec89801edb7047a779bc443b40acf066a27 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 12 Nov 2020 01:46:20 +0900 Subject: [PATCH] Fix #8350: autosummary_mock_imports causes slow down builds 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. --- CHANGES | 1 + sphinx/util/inspect.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 5e30dc7ed3d..eb041082ff8 100644 --- a/CHANGES +++ b/CHANGES @@ -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 +* #8350: 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 diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index f2cd8070bb4..9f5bf785e09 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -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