diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-04-19 00:25:05 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-04-19 14:54:54 +0900 |
commit | 841f1c7e766d623d5c071605650bedc834480fd2 (patch) | |
tree | 089489bfee5fc2e6789509a016fb9d18c2515a2b | |
parent | 61f00bf675c1a2f7955f3d342a560dc8680d87c5 (diff) | |
download | sphinx-git-841f1c7e766d623d5c071605650bedc834480fd2.tar.gz |
Fix #7479: autodoc: Sphinx builds has been slower since 3.0.0
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.
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sphinx/ext/autodoc/__init__.py | 5 | ||||
-rw-r--r-- | sphinx/ext/autodoc/mock.py | 2 |
3 files changed, 7 insertions, 1 deletions
@@ -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 diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index cfca54225..3c1f23bf1 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -578,7 +578,10 @@ class Documenter: 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: diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index 25f50d27e..98a3a3a96 100644 --- a/sphinx/ext/autodoc/mock.py +++ b/sphinx/ext/autodoc/mock.py @@ -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): @@ -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) |