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)
| 267 | |
| 268 | |
| 269 | def _get_wrapped(obj): |
| 270 | """Get the original object if wrapped in one or more @decorators |
| 271 | |
| 272 | Some objects automatically construct similar objects on any unrecognised |
| 273 | attribute access (e.g. unittest.mock.call). To protect against infinite loops, |
| 274 | this will arbitrarily cut off after 100 levels of obj.__wrapped__ |
| 275 | attribute access. --TK, Jan 2016 |
| 276 | """ |
| 277 | orig_obj = obj |
| 278 | i = 0 |
| 279 | while safe_hasattr(obj, '__wrapped__'): |
| 280 | obj = obj.__wrapped__ |
| 281 | i += 1 |
| 282 | if i > 100: |
| 283 | # __wrapped__ is probably a lie, so return the thing we started with |
| 284 | return orig_obj |
| 285 | return obj |
| 286 | |
| 287 | def find_file(obj) -> str: |
| 288 | """Find the absolute path to the file where an object was defined. |
no test coverage detected