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

Function find_source_lines

IPython/core/oinspect.py:352–381  ·  view source on GitHub ↗

Find the line number in a file where an object was defined. This is essentially a robust wrapper around `inspect.getsourcelines`. Returns None if no file can be found. Parameters ---------- obj : any Python object Returns ------- lineno : int The line numb

(obj)

Source from the content-addressed store, hash-verified

350
351
352def find_source_lines(obj):
353 """Find the line number in a file where an object was defined.
354
355 This is essentially a robust wrapper around `inspect.getsourcelines`.
356
357 Returns None if no file can be found.
358
359 Parameters
360 ----------
361 obj : any Python object
362
363 Returns
364 -------
365 lineno : int
366 The line number where the object definition starts.
367 """
368 obj = _get_wrapped(obj)
369
370 try:
371 lineno = inspect.getsourcelines(obj)[1]
372 except TypeError:
373 # For instances, try the class object like getsource() does
374 try:
375 lineno = inspect.getsourcelines(obj.__class__)[1]
376 except (OSError, TypeError):
377 return None
378 except OSError:
379 return None
380
381 return lineno
382
383
384_sentinel = object()

Callers 2

_find_edit_targetMethod · 0.90
pfileMethod · 0.85

Calls 2

_get_wrappedFunction · 0.85
getsourcelinesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…