Skip to content

Commit 9bb204d

Browse files
authored
Merge pull request #7431 from tk0miya/7422_autodoc_mock_imports_causes_ValueError
Fix #7422: autodoc: fails with ValueError when using autodoc_mock_imports
2 parents b4db396 + 63d610d commit 9bb204d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Bugs fixed
1818

1919
* #7428: py domain: a reference to class ``None`` emits a nitpicky warning
2020
* #7438: C++, fix merging overloaded functions in parallel builds.
21+
* #7422: autodoc: fails with ValueError when using autodoc_mock_imports
2122

2223
Testing
2324
--------

sphinx/util/inspect.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import warnings
1818
from functools import partial, partialmethod
1919
from inspect import ( # NOQA
20-
Parameter, isclass, ismethod, ismethoddescriptor, unwrap
20+
Parameter, isclass, ismethod, ismethoddescriptor
2121
)
2222
from io import StringIO
2323
from typing import Any, Callable, Mapping, List, Tuple
@@ -116,6 +116,15 @@ def getargspec(func: Callable) -> Any:
116116
kwonlyargs, kwdefaults, annotations)
117117

118118

119+
def unwrap(obj: Any) -> Any:
120+
"""Get an original object from wrapped object (wrapped functions)."""
121+
try:
122+
return inspect.unwrap(obj)
123+
except ValueError:
124+
# might be a mock object
125+
return obj
126+
127+
119128
def unwrap_all(obj: Any) -> Any:
120129
"""
121130
Get an original object from wrapped object (unwrapping partials, wrapped
@@ -217,7 +226,7 @@ def isattributedescriptor(obj: Any) -> bool:
217226
return True
218227
elif isdescriptor(obj):
219228
# non data descriptor
220-
unwrapped = inspect.unwrap(obj)
229+
unwrapped = unwrap(obj)
221230
if isfunction(unwrapped) or isbuiltin(unwrapped) or inspect.ismethod(unwrapped):
222231
# attribute must not be either function, builtin and method
223232
return False

0 commit comments

Comments
 (0)