Format tracebacks lines with pointing arrow, leading numbers, this assumes the stack have been extracted using stackdata. Parameters ---------- lines : list[Line]
(
lines: list[stack_data.Line],
theme: Theme,
has_colors: bool,
lvals_toks: list[TokenStream],
)
| 73 | |
| 74 | |
| 75 | def _format_traceback_lines( |
| 76 | lines: list[stack_data.Line], |
| 77 | theme: Theme, |
| 78 | has_colors: bool, |
| 79 | lvals_toks: list[TokenStream], |
| 80 | ) -> TokenStream: |
| 81 | """ |
| 82 | Format tracebacks lines with pointing arrow, leading numbers, |
| 83 | this assumes the stack have been extracted using stackdata. |
| 84 | |
| 85 | |
| 86 | Parameters |
| 87 | ---------- |
| 88 | lines : list[Line] |
| 89 | """ |
| 90 | numbers_width = INDENT_SIZE - 1 |
| 91 | tokens: TokenStream = [] |
| 92 | |
| 93 | for stack_line in lines: |
| 94 | if stack_line is stack_data.LINE_GAP: |
| 95 | toks = [(Token.LinenoEm, " (...)")] |
| 96 | tokens.extend(toks) |
| 97 | continue |
| 98 | |
| 99 | lineno = stack_line.lineno |
| 100 | line = stack_line.render(pygmented=has_colors).rstrip("\n") + "\n" |
| 101 | if stack_line.is_current: |
| 102 | # This is the line with the error |
| 103 | pad = numbers_width - len(str(lineno)) |
| 104 | toks = [ |
| 105 | (Token.LinenoEm, theme.make_arrow(pad)), |
| 106 | (Token.LinenoEm, str(lineno)), |
| 107 | (Token, " "), |
| 108 | (Token, line), |
| 109 | ] |
| 110 | else: |
| 111 | num = "%*s" % (numbers_width, lineno) |
| 112 | toks = [ |
| 113 | (Token.LinenoEm, str(num)), |
| 114 | (Token, " "), |
| 115 | (Token, line), |
| 116 | ] |
| 117 | |
| 118 | tokens.extend(toks) |
| 119 | if lvals_toks and stack_line.is_current: |
| 120 | for lv in lvals_toks: |
| 121 | tokens.append((Token, " " * INDENT_SIZE)) |
| 122 | tokens.extend(lv) |
| 123 | tokens.append((Token, "\n")) |
| 124 | # strip the last newline |
| 125 | tokens = tokens[:-1] |
| 126 | |
| 127 | return tokens |
| 128 | |
| 129 | |
| 130 | # some internal-use functions |
nothing calls this directly
no test coverage detected
searching dependent graphs…