diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index 71d079c88..cc6e4b366 100644 --- a/sphinx/ext/autodoc/mock.py +++ b/sphinx/ext/autodoc/mock.py @@ -9,7 +9,7 @@ from types import MethodType, ModuleType from typing import Any, Generator, Iterator, List, Optional, Sequence, Tuple, Union from sphinx.util import logging -from sphinx.util.inspect import safe_getattr +from sphinx.util.inspect import isboundmethod, safe_getattr logger = logging.getLogger(__name__) @@ -129,14 +129,6 @@ class MockFinder(MetaPathFinder): sys.modules.pop(modname, None) -def isboundmethod(method: MethodType) -> bool: - """Check if the method is a bound method.""" - try: - return method.__self__ is not None - except AttributeError: - return False - - @contextlib.contextmanager def mock(modnames: List[str]) -> Generator[None, None, None]: """Insert mock modules during context:: diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 5b4e2586e..e226c74dc 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -13,7 +13,7 @@ from functools import partial, partialmethod from importlib import import_module from inspect import Parameter, isclass, ismethod, ismethoddescriptor, ismodule # NOQA from io import StringIO -from types import ModuleType +from types import MethodType, ModuleType from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple, Type, cast from sphinx.deprecation import RemovedInSphinx50Warning @@ -303,6 +303,14 @@ def isabstractmethod(obj: Any) -> bool: return safe_getattr(obj, '__isabstractmethod__', False) is True +def isboundmethod(method: MethodType) -> bool: + """Check if the method is a bound method.""" + try: + return method.__self__ is not None + except AttributeError: + return False + + def is_cython_function_or_method(obj: Any) -> bool: """Check if the object is a function or method in cython.""" try: