MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getsourcelines

Function getsourcelines

tools/python-3.11.9-amd64/Lib/inspect.py:1231–1250  ·  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

(object)

Source from the content-addressed store, hash-verified

1229 return lines[:blockfinder.last]
1230
1231def getsourcelines(object):
1232 """Return a list of source lines and starting line number for an object.
1233
1234 The argument may be a module, class, method, function, traceback, frame,
1235 or code object. The source code is returned as a list of the lines
1236 corresponding to the object and the line number indicates where in the
1237 original source file the first line of code was found. An OSError is
1238 raised if the source code cannot be retrieved."""
1239 object = unwrap(object)
1240 lines, lnum = findsource(object)
1241
1242 if istraceback(object):
1243 object = object.tb_frame
1244
1245 # for module or frame that corresponds to module, return all source lines
1246 if (ismodule(object) or
1247 (isframe(object) and object.f_code.co_name == "<module>")):
1248 return lines, 0
1249 else:
1250 return getblock(lines[lnum:]), lnum + 1
1251
1252def getsource(object):
1253 """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