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

Method format

Lib/traceback.py:745–791  ·  view source on GitHub ↗

Format the stack ready for printing. Returns a list of strings ready for printing. Each string in the resulting list corresponds to a single frame from the stack. Each string ends in a newline; the strings may contain internal newlines as well, for those items with

(self, **kwargs)

Source from the content-addressed store, hash-verified

743 return False
744
745 def format(self, **kwargs):
746 """Format the stack ready for printing.
747
748 Returns a list of strings ready for printing. Each string in the
749 resulting list corresponds to a single frame from the stack.
750 Each string ends in a newline; the strings may contain internal
751 newlines as well, for those items with source text lines.
752
753 For long sequences of the same frame and line, the first few
754 repetitions are shown, followed by a summary line stating the exact
755 number of further repetitions.
756 """
757 colorize = kwargs.get("colorize", False)
758 result = []
759 last_file = None
760 last_line = None
761 last_name = None
762 count = 0
763 for frame_summary in self:
764 formatted_frame = self.format_frame_summary(frame_summary, colorize=colorize)
765 if formatted_frame is None:
766 continue
767 if (last_file is None or last_file != frame_summary.filename or
768 last_line is None or last_line != frame_summary.lineno or
769 last_name is None or last_name != frame_summary.name):
770 if count > _RECURSIVE_CUTOFF:
771 count -= _RECURSIVE_CUTOFF
772 result.append(
773 f' [Previous line repeated {count} more '
774 f'time{"s" if count > 1 else ""}]\n'
775 )
776 last_file = frame_summary.filename
777 last_line = frame_summary.lineno
778 last_name = frame_summary.name
779 count = 0
780 count += 1
781 if count > _RECURSIVE_CUTOFF:
782 continue
783 result.append(formatted_frame)
784
785 if count > _RECURSIVE_CUTOFF:
786 count -= _RECURSIVE_CUTOFF
787 result.append(
788 f' [Previous line repeated {count} more '
789 f'time{"s" if count > 1 else ""}]\n'
790 )
791 return result
792
793
794def _byte_offset_to_character_offset(str, offset):

Callers 8

print_listFunction · 0.45
format_listFunction · 0.45
format_tbFunction · 0.45
__repr__Method · 0.45
format_frame_summaryMethod · 0.45
format_exception_onlyMethod · 0.45
_format_syntax_errorMethod · 0.45
formatMethod · 0.45

Calls 3

format_frame_summaryMethod · 0.95
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected