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

Function find_file

IPython/core/oinspect.py:287–319  ·  view source on GitHub ↗

Find the absolute path to the file where an object was defined. This is essentially a robust wrapper around `inspect.getabsfile`. Returns None if no file can be found. Parameters ---------- obj : any Python object Returns ------- fname : str The absolute pat

(obj)

Source from the content-addressed store, hash-verified

285 return obj
286
287def find_file(obj) -> str:
288 """Find the absolute path to the file where an object was defined.
289
290 This is essentially a robust wrapper around `inspect.getabsfile`.
291
292 Returns None if no file can be found.
293
294 Parameters
295 ----------
296 obj : any Python object
297
298 Returns
299 -------
300 fname : str
301 The absolute path to the file where the object was defined.
302 """
303 obj = _get_wrapped(obj)
304
305 fname = None
306 try:
307 fname = inspect.getabsfile(obj)
308 except TypeError:
309 # For an instance, the file that matters is where its class was
310 # declared.
311 if hasattr(obj, '__class__'):
312 try:
313 fname = inspect.getabsfile(obj.__class__)
314 except TypeError:
315 # Can happen for builtins
316 pass
317 except:
318 pass
319 return cast_unicode(fname)
320
321
322def find_source_lines(obj):

Callers 4

_find_edit_targetMethod · 0.90
get_encodingFunction · 0.85
pfileMethod · 0.85
_infoMethod · 0.85

Calls 2

cast_unicodeFunction · 0.90
_get_wrappedFunction · 0.85

Tested by

no test coverage detected