MCPcopy Create free account
hub / github.com/ipython/ipython / _get_wrapped

Function _get_wrapped

IPython/core/oinspect.py:269–285  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

267
268
269def _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
287def find_file(obj) -> str:
288 """Find the absolute path to the file where an object was defined.

Callers 3

getsourceFunction · 0.85
find_fileFunction · 0.85
find_source_linesFunction · 0.85

Calls 1

safe_hasattrFunction · 0.90

Tested by

no test coverage detected