MCPcopy Index your code
hub / github.com/RustPython/RustPython / getsourcelines

Function getsourcelines

Lib/inspect.py:1134–1153  ·  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

1132 return lines[:blockfinder.last]
1133
1134def getsourcelines(object):
1135 """Return a list of source lines and starting line number for an object.
1136
1137 The argument may be a module, class, method, function, traceback, frame,
1138 or code object. The source code is returned as a list of the lines
1139 corresponding to the object and the line number indicates where in the
1140 original source file the first line of code was found. An OSError is
1141 raised if the source code cannot be retrieved."""
1142 object = unwrap(object)
1143 lines, lnum = findsource(object)
1144
1145 if istraceback(object):
1146 object = object.tb_frame
1147
1148 # for module or frame that corresponds to module, return all source lines
1149 if (ismodule(object) or
1150 (isframe(object) and object.f_code.co_name == "<module>")):
1151 return lines, 0
1152 else:
1153 return getblock(lines[lnum:]), lnum + 1
1154
1155def getsource(object):
1156 """Return the text of the source code for an object.

Callers 1

getsourceFunction · 0.70

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