Get the original object if wrapped in one or more @decorators Some objects automatically construct similar objects on any unrecognised attribute access (e.g. unittest.mock.call). To protect against infinite loops, this will arbitrarily cut off after 100 levels of obj.__wrapped__ att
(obj)
| 297 | isinstance(obj, _builtin_func_type) or isinstance(obj, _builtin_meth_type)) |
| 298 | |
| 299 | def _get_wrapped(obj): |
| 300 | """Get the original object if wrapped in one or more @decorators |
| 301 | |
| 302 | Some objects automatically construct similar objects on any unrecognised |
| 303 | attribute access (e.g. unittest.mock.call). To protect against infinite loops, |
| 304 | this will arbitrarily cut off after 100 levels of obj.__wrapped__ |
| 305 | attribute access. --TK, Jan 2016 |
| 306 | """ |
| 307 | orig_obj = obj |
| 308 | i = 0 |
| 309 | while safe_hasattr(obj, '__wrapped__'): |
| 310 | obj = obj.__wrapped__ |
| 311 | i += 1 |
| 312 | if i > 100: |
| 313 | # __wrapped__ is probably a lie, so return the thing we started with |
| 314 | return orig_obj |
| 315 | return obj |
| 316 | |
| 317 | def find_file(obj) -> Optional[str]: |
| 318 | """Find the absolute path to the file where an object was defined. |
no test coverage detected
searching dependent graphs…