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

Function getframeinfo

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

(frame, context=1)

Source from the content-addressed store, hash-verified

1656 return next(itertools.islice(positions_gen, instruction_index // 2, None))
1657
1658def getframeinfo(frame, context=1):
1659 """Get information about a frame or traceback object.
1660
1661 A tuple of five things is returned: the filename, the line number of
1662 the current line, the function name, a list of lines of context from
1663 the source code, and the index of the current line within that list.
1664 The optional second argument specifies the number of lines of context
1665 to return, which are centered around the current line."""
1666 if istraceback(frame):
1667 positions = _get_code_position_from_tb(frame)
1668 lineno = frame.tb_lineno
1669 frame = frame.tb_frame
1670 else:
1671 lineno = frame.f_lineno
1672 positions = _get_code_position(frame.f_code, frame.f_lasti)
1673
1674 if positions[0] is None:
1675 frame, *positions = (frame, lineno, *positions[1:])
1676 else:
1677 frame, *positions = (frame, *positions)
1678
1679 lineno = positions[0]
1680
1681 if not isframe(frame):
1682 raise TypeError('{!r} is not a frame or traceback object'.format(frame))
1683
1684 filename = getsourcefile(frame) or getfile(frame)
1685 if context > 0:
1686 start = lineno - 1 - context//2
1687 try:
1688 lines, lnum = findsource(frame)
1689 except OSError:
1690 lines = index = None
1691 else:
1692 start = max(0, min(start, len(lines) - context))
1693 lines = lines[start:start+context]
1694 index = lineno - 1 - start
1695 else:
1696 lines = index = None
1697
1698 return Traceback(filename, lineno, frame.f_code.co_name, lines,
1699 index, positions=dis.Positions(*positions))
1700
1701def getlineno(frame):
1702 """Get the line number from a frame object, allowing for optimization."""

Callers 2

getouterframesFunction · 0.85
getinnerframesFunction · 0.85

Calls 11

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

Tested by

no test coverage detected