mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7431 from tk0miya/7422_autodoc_mock_imports_causes_ValueError
Fix #7422: autodoc: fails with ValueError when using autodoc_mock_imports
This commit is contained in:
commit
9bb204dcab
1
CHANGES
1
CHANGES
@ -18,6 +18,7 @@ Bugs fixed
|
|||||||
|
|
||||||
* #7428: py domain: a reference to class ``None`` emits a nitpicky warning
|
* #7428: py domain: a reference to class ``None`` emits a nitpicky warning
|
||||||
* #7438: C++, fix merging overloaded functions in parallel builds.
|
* #7438: C++, fix merging overloaded functions in parallel builds.
|
||||||
|
* #7422: autodoc: fails with ValueError when using autodoc_mock_imports
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -17,7 +17,7 @@ import typing
|
|||||||
import warnings
|
import warnings
|
||||||
from functools import partial, partialmethod
|
from functools import partial, partialmethod
|
||||||
from inspect import ( # NOQA
|
from inspect import ( # NOQA
|
||||||
Parameter, isclass, ismethod, ismethoddescriptor, unwrap
|
Parameter, isclass, ismethod, ismethoddescriptor
|
||||||
)
|
)
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from typing import Any, Callable, Mapping, List, Tuple
|
from typing import Any, Callable, Mapping, List, Tuple
|
||||||
@ -116,6 +116,15 @@ def getargspec(func: Callable) -> Any:
|
|||||||
kwonlyargs, kwdefaults, annotations)
|
kwonlyargs, kwdefaults, annotations)
|
||||||
|
|
||||||
|
|
||||||
|
def unwrap(obj: Any) -> Any:
|
||||||
|
"""Get an original object from wrapped object (wrapped functions)."""
|
||||||
|
try:
|
||||||
|
return inspect.unwrap(obj)
|
||||||
|
except ValueError:
|
||||||
|
# might be a mock object
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
def unwrap_all(obj: Any) -> Any:
|
def unwrap_all(obj: Any) -> Any:
|
||||||
"""
|
"""
|
||||||
Get an original object from wrapped object (unwrapping partials, wrapped
|
Get an original object from wrapped object (unwrapping partials, wrapped
|
||||||
@ -217,7 +226,7 @@ def isattributedescriptor(obj: Any) -> bool:
|
|||||||
return True
|
return True
|
||||||
elif isdescriptor(obj):
|
elif isdescriptor(obj):
|
||||||
# non data descriptor
|
# non data descriptor
|
||||||
unwrapped = inspect.unwrap(obj)
|
unwrapped = unwrap(obj)
|
||||||
if isfunction(unwrapped) or isbuiltin(unwrapped) or inspect.ismethod(unwrapped):
|
if isfunction(unwrapped) or isbuiltin(unwrapped) or inspect.ismethod(unwrapped):
|
||||||
# attribute must not be either function, builtin and method
|
# attribute must not be either function, builtin and method
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user