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

Function getframeinfo

Lib/inspect.py:1568–1609  ·  view source on GitHub ↗

Get information about a frame or traceback object. A tuple of five things is returned: the filename, the line number of the current line, the function name, a list of lines of context from the source code, and the index of the current line within that list. The optional second argum

(frame, context=1)

Source from the content-addressed store, hash-verified

1566 return next(itertools.islice(positions_gen, instruction_index // 2, None))
1567
1568def getframeinfo(frame, context=1):
1569 """Get information about a frame or traceback object.
1570
1571 A tuple of five things is returned: the filename, the line number of
1572 the current line, the function name, a list of lines of context from
1573 the source code, and the index of the current line within that list.
1574 The optional second argument specifies the number of lines of context
1575 to return, which are centered around the current line."""
1576 if istraceback(frame):
1577 positions = _get_code_position_from_tb(frame)
1578 lineno = frame.tb_lineno
1579 frame = frame.tb_frame
1580 else:
1581 lineno = frame.f_lineno
1582 positions = _get_code_position(frame.f_code, frame.f_lasti)
1583
1584 if positions[0] is None:
1585 frame, *positions = (frame, lineno, *positions[1:])
1586 else:
1587 frame, *positions = (frame, *positions)
1588
1589 lineno = positions[0]
1590
1591 if not isframe(frame):
1592 raise TypeError('{!r} is not a frame or traceback object'.format(frame))
1593
1594 filename = getsourcefile(frame) or getfile(frame)
1595 if context > 0:
1596 start = lineno - 1 - context//2
1597 try:
1598 lines, lnum = findsource(frame)
1599 except OSError:
1600 lines = index = None
1601 else:
1602 start = max(0, min(start, len(lines) - context))
1603 lines = lines[start:start+context]
1604 index = lineno - 1 - start
1605 else:
1606 lines = index = None
1607
1608 return Traceback(filename, lineno, frame.f_code.co_name, lines,
1609 index, positions=dis.Positions(*positions))
1610
1611def getlineno(frame):
1612 """Get the line number from a frame object, allowing for optimization."""

Callers 2

getouterframesFunction · 0.85
getinnerframesFunction · 0.85

Calls 12

istracebackFunction · 0.85
isframeFunction · 0.85
getsourcefileFunction · 0.85
getfileFunction · 0.85
findsourceFunction · 0.85
maxFunction · 0.85
minFunction · 0.85
lenFunction · 0.85
_get_code_positionFunction · 0.70
TracebackClass · 0.70
formatMethod · 0.45

Tested by

no test coverage detected