MCPcopy Index your code
hub / github.com/RustPython/RustPython / output_line

Method output_line

Lib/traceback.py:640–688  ·  view source on GitHub ↗

output all_lines[lineno] along with carets

(lineno)

Source from the content-addressed store, hash-verified

638 significant_lines.discard(len(all_lines))
639
640 def output_line(lineno):
641 """output all_lines[lineno] along with carets"""
642 result.append(all_lines[lineno] + "\n")
643 if not show_carets:
644 return
645 num_spaces = len(all_lines[lineno]) - len(all_lines[lineno].lstrip())
646 carets = []
647 num_carets = dp_end_offset if lineno == len(all_lines) - 1 else _display_width(all_lines[lineno])
648 # compute caret character for each position
649 for col in range(num_carets):
650 if col < num_spaces or (lineno == 0 and col < dp_start_offset):
651 # before first non-ws char of the line, or before start of instruction
652 carets.append(' ')
653 elif anchors and (
654 lineno > anchors.left_end_lineno or
655 (lineno == anchors.left_end_lineno and col >= anchors_left_end_offset)
656 ) and (
657 lineno < anchors.right_start_lineno or
658 (lineno == anchors.right_start_lineno and col < anchors_right_start_offset)
659 ):
660 # within anchors
661 carets.append(secondary_char)
662 else:
663 carets.append(primary_char)
664 if colorize:
665 # Replace the previous line with a red version of it only in the parts covered
666 # by the carets.
667 line = result[-1]
668 colorized_line_parts = []
669 colorized_carets_parts = []
670
671 for color, group in itertools.groupby(itertools.zip_longest(line, carets, fillvalue=""), key=lambda x: x[1]):
672 caret_group = list(group)
673 if color == "^":
674 colorized_line_parts.append(theme.error_highlight + "".join(char for char, _ in caret_group) + theme.reset)
675 colorized_carets_parts.append(theme.error_highlight + "".join(caret for _, caret in caret_group) + theme.reset)
676 elif color == "~":
677 colorized_line_parts.append(theme.error_range + "".join(char for char, _ in caret_group) + theme.reset)
678 colorized_carets_parts.append(theme.error_range + "".join(caret for _, caret in caret_group) + theme.reset)
679 else:
680 colorized_line_parts.append("".join(char for char, _ in caret_group))
681 colorized_carets_parts.append("".join(caret for _, caret in caret_group))
682
683 colorized_line = "".join(colorized_line_parts)
684 colorized_carets = "".join(colorized_carets_parts)
685 result[-1] = colorized_line
686 result.append(colorized_carets + "\n")
687 else:
688 result.append("".join(carets) + "\n")
689
690 # display significant lines
691 sig_lines_list = sorted(significant_lines)

Callers

nothing calls this directly

Calls 7

lenFunction · 0.85
_display_widthFunction · 0.85
listClass · 0.85
groupbyMethod · 0.80
appendMethod · 0.45
lstripMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected