MCPcopy Create free account
hub / github.com/bloomberg/pystack / format_frame

Function format_frame

src/pystack/traceback_formatter.py:20–52  ·  view source on GitHub ↗
(frame: PyFrame)

Source from the content-addressed store, hash-verified

18
19
20def format_frame(frame: PyFrame) -> Iterable[str]:
21 code: PyCodeObject = frame.code
22 function = colored(code.scope, "yellow")
23 yield (
24 f' {colored("(Python)", "green")} File "{code.filename}"'
25 f", line {code.location.lineno}, in {function}"
26 )
27 if os.path.exists(code.filename):
28 with open(code.filename, "r") as fp:
29 lines = fp.readlines()
30 source = lines[code.location.lineno - 1]
31 line_start, line_end, col_start, col_end = code.location
32 if col_start == col_end == 0:
33 yield f" {source.strip()}"
34 else:
35 if line_end != line_start:
36 col_end = len(source)
37 a = source[:col_start]
38 b = source[col_start:col_end]
39 c = source[col_end:]
40 final = f'{a}{colored(b, color="blue")}{c}'
41 yield f" {final.strip()}"
42
43 if frame.arguments:
44 yield f" {colored('Arguments:', attrs=['faint'])}"
45 for argument, value in frame.arguments.items():
46 normalized_value = repr(value)[1:-1]
47 yield f" {argument}: {normalized_value}"
48 if frame.locals:
49 yield f" {colored('Locals:', attrs=['faint'])}"
50 for local, value in frame.locals.items():
51 normalized_value = repr(value)[1:-1]
52 yield f" {local}: {value}"
53
54
55def _are_the_stacks_mergeable(thread: PyThread) -> bool:

Callers 2

format_threadFunction · 0.85
_format_merged_stacksFunction · 0.85

Calls 2

coloredFunction · 0.85
existsMethod · 0.80

Tested by

no test coverage detected