Move method isboundmethod() into sphinx/util/inspect.py.

This commit is contained in:
Christian Walch 2022-04-01 06:14:35 +02:00
parent a939dd4345
commit 439485e837
2 changed files with 10 additions and 10 deletions

View File

@ -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::

View File

@ -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: