MCPcopy Index your code
hub / github.com/ipython/ipython / find_file

Function find_file

IPython/core/oinspect.py:317–349  ·  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 p

(obj)

Source from the content-addressed store, hash-verified

315 return obj
316
317def find_file(obj) -> Optional[str]:
318 """Find the absolute path to the file where an object was defined.
319
320 This is essentially a robust wrapper around `inspect.getabsfile`.
321
322 Returns None if no file can be found.
323
324 Parameters
325 ----------
326 obj : any Python object
327
328 Returns
329 -------
330 fname : str
331 The absolute path to the file where the object was defined.
332 """
333 obj = _get_wrapped(obj)
334
335 fname: Optional[str] = None
336 try:
337 fname = inspect.getabsfile(obj)
338 except TypeError:
339 # For an instance, the file that matters is where its class was
340 # declared.
341 try:
342 fname = inspect.getabsfile(obj.__class__)
343 except (OSError, TypeError):
344 # Can happen for builtins
345 pass
346 except OSError:
347 pass
348
349 return fname
350
351
352def find_source_lines(obj):

Callers 4

_find_edit_targetMethod · 0.90
get_encodingFunction · 0.85
pfileMethod · 0.85
infoMethod · 0.85

Calls 1

_get_wrappedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…