(frame: PyFrame)
| 18 | |
| 19 | |
| 20 | def 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 | |
| 55 | def _are_the_stacks_mergeable(thread: PyThread) -> bool: |
no test coverage detected