MCPcopy Index your code
hub / github.com/python/cpython / getsourcelines

Function getsourcelines

Lib/inspect.py:1158–1177  ·  view source on GitHub ↗

Return a list of source lines and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the o

(object)

Source from the content-addressed store, hash-verified

1156 return lines[:blockfinder.last]
1157
1158def getsourcelines(object):
1159 """Return a list of source lines and starting line number for an object.
1160
1161 The argument may be a module, class, method, function, traceback, frame,
1162 or code object. The source code is returned as a list of the lines
1163 corresponding to the object and the line number indicates where in the
1164 original source file the first line of code was found. An OSError is
1165 raised if the source code cannot be retrieved."""
1166 object = unwrap(object)
1167 lines, lnum = findsource(object)
1168
1169 if istraceback(object):
1170 object = object.tb_frame
1171
1172 # for module or frame that corresponds to module, return all source lines
1173 if (ismodule(object) or
1174 (isframe(object) and object.f_code.co_name == "<module>")):
1175 return lines, 0
1176 else:
1177 return getblock(lines[lnum:]), lnum + 1
1178
1179def getsource(object):
1180 """Return the text of the source code for an object.

Callers 1

getsourceFunction · 0.85

Calls 6

findsourceFunction · 0.85
istracebackFunction · 0.85
ismoduleFunction · 0.85
isframeFunction · 0.85
getblockFunction · 0.85
unwrapFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…