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

Function find_source_lines

IPython/core/oinspect.py:322–352  ·  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 number

(obj)

Source from the content-addressed store, hash-verified

320
321
322def find_source_lines(obj):
323 """Find the line number in a file where an object was defined.
324
325 This is essentially a robust wrapper around `inspect.getsourcelines`.
326
327 Returns None if no file can be found.
328
329 Parameters
330 ----------
331 obj : any Python object
332
333 Returns
334 -------
335 lineno : int
336 The line number where the object definition starts.
337 """
338 obj = _get_wrapped(obj)
339
340 try:
341 try:
342 lineno = inspect.getsourcelines(obj)[1]
343 except TypeError:
344 # For instances, try the class object like getsource() does
345 if hasattr(obj, '__class__'):
346 lineno = inspect.getsourcelines(obj.__class__)[1]
347 else:
348 lineno = None
349 except:
350 return None
351
352 return lineno
353
354class Inspector(Colorable):
355

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