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],
)
| 27 | |
| 28 | |
| 29 | def _format_traceback_lines( |
| 30 | lines: list[stack_data.Line], |
| 31 | theme: Theme, |
| 32 | has_colors: bool, |
| 33 | lvals_toks: list[TokenStream], |
| 34 | ) -> TokenStream: |
| 35 | """ |
| 36 | Format tracebacks lines with pointing arrow, leading numbers, |
| 37 | this assumes the stack have been extracted using stackdata. |
| 38 | |
| 39 | |
| 40 | Parameters |
| 41 | ---------- |
| 42 | lines : list[Line] |
| 43 | """ |
| 44 | numbers_width = INDENT_SIZE - 1 |
| 45 | tokens: TokenStream = [(Token, "\n")] |
| 46 | |
| 47 | for stack_line in lines: |
| 48 | if stack_line is stack_data.LINE_GAP: |
| 49 | toks = [(Token.LinenoEm, " (...)")] |
| 50 | tokens.extend(toks) |
| 51 | continue |
| 52 | |
| 53 | lineno = stack_line.lineno |
| 54 | line = stack_line.render(pygmented=has_colors).rstrip("\n") + "\n" |
| 55 | if stack_line.is_current: |
| 56 | # This is the line with the error |
| 57 | pad = numbers_width - len(str(lineno)) |
| 58 | toks = [ |
| 59 | (Token.Prompt, theme.make_arrow(3)), |
| 60 | (Token, " "), |
| 61 | (Token, line), |
| 62 | ] |
| 63 | else: |
| 64 | # num = "%*s" % (numbers_width, lineno) |
| 65 | toks = [ |
| 66 | # (Token.LinenoEm, str(num)), |
| 67 | (Token, "..."), |
| 68 | (Token, " "), |
| 69 | (Token, line), |
| 70 | ] |
| 71 | |
| 72 | tokens.extend(toks) |
| 73 | if lvals_toks and stack_line.is_current: |
| 74 | for lv in lvals_toks: |
| 75 | tokens.append((Token, " " * INDENT_SIZE)) |
| 76 | tokens.extend(lv) |
| 77 | tokens.append((Token, "\n")) |
| 78 | # strip the last newline |
| 79 | tokens = tokens[:-1] |
| 80 | |
| 81 | return tokens |
| 82 | |
| 83 | |
| 84 | class DocTB(TBTools): |
no test coverage detected
searching dependent graphs…