MCPcopy Index your code
hub / github.com/ipython/ipython / _format_traceback_lines

Function _format_traceback_lines

IPython/core/doctb.py:29–81  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

27
28
29def _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
84class DocTB(TBTools):

Callers 2

format_recordMethod · 0.70
format_recordMethod · 0.70

Calls 2

renderMethod · 0.80
make_arrowMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…