Format tracebacks lines with pointing arrow, leading numbers This should be equivalent to _format_traceback_lines, but does not rely on stackdata to format the lines This is due to the fact that stackdata may be slow on super long and complex files. Parameters ==========
(
lnum: int,
index: int,
lines: list[tuple[str, tuple[str, bool]]],
lvals_toks: list[TokenStream],
theme: Theme,
)
| 218 | |
| 219 | |
| 220 | def _simple_format_traceback_lines( |
| 221 | lnum: int, |
| 222 | index: int, |
| 223 | lines: list[tuple[str, tuple[str, bool]]], |
| 224 | lvals_toks: list[TokenStream], |
| 225 | theme: Theme, |
| 226 | ) -> TokenStream: |
| 227 | """ |
| 228 | Format tracebacks lines with pointing arrow, leading numbers |
| 229 | |
| 230 | This should be equivalent to _format_traceback_lines, but does not rely on stackdata |
| 231 | to format the lines |
| 232 | |
| 233 | This is due to the fact that stackdata may be slow on super long and complex files. |
| 234 | |
| 235 | Parameters |
| 236 | ========== |
| 237 | |
| 238 | lnum: int |
| 239 | number of the target line of code. |
| 240 | index: int |
| 241 | which line in the list should be highlighted. |
| 242 | lines: list[string] |
| 243 | lvals_toks: pairs of token type and str |
| 244 | Values of local variables, already colored, to inject just after the error line. |
| 245 | """ |
| 246 | for item in lvals_toks: |
| 247 | assert isinstance(item, list) |
| 248 | for subit in item: |
| 249 | assert isinstance(subit[1], str) |
| 250 | |
| 251 | numbers_width = INDENT_SIZE - 1 |
| 252 | res_toks: TokenStream = [] |
| 253 | for i, (line, (new_line, err)) in enumerate(lines, lnum - index): |
| 254 | if not err: |
| 255 | line = new_line |
| 256 | |
| 257 | colored_line = line |
| 258 | if i == lnum: |
| 259 | # This is the line with the error |
| 260 | pad = numbers_width - len(str(i)) |
| 261 | line_toks = [ |
| 262 | (Token.LinenoEm, theme.make_arrow(pad)), |
| 263 | (Token.LinenoEm, str(lnum)), |
| 264 | (Token, " "), |
| 265 | (Token, colored_line), |
| 266 | ] |
| 267 | else: |
| 268 | padding_num = "%*s" % (numbers_width, i) |
| 269 | |
| 270 | line_toks = [ |
| 271 | (Token.LinenoEm, padding_num), |
| 272 | (Token, " "), |
| 273 | (Token, colored_line), |
| 274 | ] |
| 275 | res_toks.extend(line_toks) |
| 276 | |
| 277 | if lvals_toks and i == lnum: |
no test coverage detected
searching dependent graphs…