|
17 | 17 | import warnings
|
18 | 18 | from functools import partial, partialmethod
|
19 | 19 | from inspect import ( # NOQA
|
20 |
| - Parameter, isclass, ismethod, ismethoddescriptor, unwrap |
| 20 | + Parameter, isclass, ismethod, ismethoddescriptor |
21 | 21 | )
|
22 | 22 | from io import StringIO
|
23 | 23 | from typing import Any, Callable, Mapping, List, Tuple
|
@@ -116,6 +116,15 @@ def getargspec(func: Callable) -> Any:
|
116 | 116 | kwonlyargs, kwdefaults, annotations)
|
117 | 117 |
|
118 | 118 |
|
| 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 | + |
119 | 128 | def unwrap_all(obj: Any) -> Any:
|
120 | 129 | """
|
121 | 130 | Get an original object from wrapped object (unwrapping partials, wrapped
|
@@ -217,7 +226,7 @@ def isattributedescriptor(obj: Any) -> bool:
|
217 | 226 | return True
|
218 | 227 | elif isdescriptor(obj):
|
219 | 228 | # non data descriptor
|
220 |
| - unwrapped = inspect.unwrap(obj) |
| 229 | + unwrapped = unwrap(obj) |
221 | 230 | if isfunction(unwrapped) or isbuiltin(unwrapped) or inspect.ismethod(unwrapped):
|
222 | 231 | # attribute must not be either function, builtin and method
|
223 | 232 | return False
|
|
0 commit comments