diff --git a/CHANGES b/CHANGES index b0053fb8104..c1baaf14cdd 100644 --- a/CHANGES +++ b/CHANGES @@ -62,6 +62,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 diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index ac4c7ed4bd5..4a8bd0e2750 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -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: diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index 25f50d27e79..98a3a3a96e5 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)