From 0576ebe6df765ed785606a8370608d0e273a3370 Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Thu, 12 Mar 2026 23:03:11 -0300 Subject: [PATCH 1/4] Fix typos and stale docstrings in Lib/traceback.py. --- Lib/traceback.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 956cab49131990..4f7145eb1e9a96 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -83,10 +83,11 @@ def extract_tb(tb, limit=None): This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a FrameSummary object - containing attributes filename, lineno, name, and line - representing the information that is usually printed for a stack - trace. The line is a string with leading and trailing - whitespace stripped; if the source is not available it is None. + containing attributes filename, lineno, name, line, end_lineno, + colno, and end_colno representing the information that is + usually printed for a stack trace. The line is a string with + leading and trailing whitespace stripped; if the source is not + available it is None. """ return StackSummary._extract_from_extended_frame_gen( _walk_tb_with_full_positions(tb), limit=limit) @@ -263,9 +264,8 @@ def extract_stack(f=None, limit=None): The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for - print_stack(). Each item in the list is a quadruple (filename, - line number, function name, text), and the entries are in order - from oldest to newest stack frame. + print_stack(). Each item in the list is a FrameSummary object, + and the entries are in order from oldest to newest stack frame. """ if f is None: f = sys._getframe().f_back @@ -294,7 +294,7 @@ class FrameSummary: - :attr:`name` The name of the function or method that was executing when the frame was captured. - :attr:`line` The text from the linecache module for the - of code that was running when the frame was captured. + code that was running when the frame was captured. - :attr:`locals` Either None if locals were not supplied, or a dict mapping the name to the repr() of the variable. - :attr:`end_lineno` The last line number of the source code for this frame. @@ -974,9 +974,9 @@ def setup_positions(expr, force_valid=True): _WIDE_CHAR_SPECIFIERS = "WF" def _display_width(line, offset=None): - """Calculate the extra amount of width space the given source - code segment might take if it were to be displayed on a fixed - width output device. Supports wide unicode characters and emojis.""" + """Calculate the amount of width space the given source code + segment might take if it were to be displayed on a fixed width + output device. Supports wide unicode characters and emojis.""" if offset is None: offset = len(line) @@ -1060,7 +1060,7 @@ class TracebackException: def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10, save_exc_type=True, _seen=None): - # NB: we need to accept exc_traceback, exc_value, exc_traceback to + # NB: we need to accept exc_type, exc_value, exc_traceback to # permit backwards compat with the existing API, otherwise we # need stub thunk objects just to glue it together. # Handle loops in __cause__ or __context__. From 04baa567d0343d7b1c729dac77800222b5f8ed72 Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Sun, 22 Mar 2026 12:01:49 -0300 Subject: [PATCH 2/4] Avoid unnecessary word placement moves. --- Lib/traceback.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 4f7145eb1e9a96..b3d2b4bc46986a 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -974,9 +974,9 @@ def setup_positions(expr, force_valid=True): _WIDE_CHAR_SPECIFIERS = "WF" def _display_width(line, offset=None): - """Calculate the amount of width space the given source code - segment might take if it were to be displayed on a fixed width - output device. Supports wide unicode characters and emojis.""" + """Calculate the amount of width space the given source + code segment might take if it were to be displayed on a fixed + width output device. Supports wide unicode characters and emojis.""" if offset is None: offset = len(line) From 5cff3a18c402ea5e25ee01ca901fcd6e5c1040fe Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:34:39 -0300 Subject: [PATCH 3/4] Fix a few more stale docs and typos. --- Doc/library/traceback.rst | 10 ++++++---- Lib/traceback.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst index b5464ac55ddfa9..a262273c0fb6b5 100644 --- a/Doc/library/traceback.rst +++ b/Doc/library/traceback.rst @@ -149,7 +149,9 @@ Module-Level Functions the same meaning as for :func:`print_tb`. A "pre-processed" stack trace entry is a :class:`FrameSummary` object containing attributes :attr:`~FrameSummary.filename`, :attr:`~FrameSummary.lineno`, - :attr:`~FrameSummary.name`, and :attr:`~FrameSummary.line` representing the + :attr:`~FrameSummary.name`, :attr:`~FrameSummary.line`, + :attr:`~FrameSummary.end_lineno`, :attr:`~FrameSummary.colno`, and + :attr:`~FrameSummary.end_colno` representing the information that is usually printed for a stack trace. @@ -181,7 +183,7 @@ Module-Level Functions .. function:: format_exception_only(exc, /[, value], *, show_group=False) Format the exception part of a traceback using an exception value such as - given by :data:`sys.last_value`. The return value is a list of strings, each + given by :data:`sys.last_exc`. The return value is a list of strings, each ending in a newline. The list contains the exception's message, which is normally a single string; however, for :exc:`SyntaxError` exceptions, it contains several lines that (when printed) display detailed information @@ -347,7 +349,7 @@ the module-level functions described above. .. attribute:: exc_type - The class of the original traceback. + The class of the original exception. .. deprecated:: 3.13 @@ -391,7 +393,7 @@ the module-level functions described above. For syntax errors - the compiler error message. - .. classmethod:: from_exception(exc, *, limit=None, lookup_lines=True, capture_locals=False) + .. classmethod:: from_exception(exc, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10) Capture an exception for later rendering. *limit*, *lookup_lines* and *capture_locals* are as for the :class:`StackSummary` class. diff --git a/Lib/traceback.py b/Lib/traceback.py index b3d2b4bc46986a..08e88aac55d566 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -293,7 +293,7 @@ class FrameSummary: active when the frame was captured. - :attr:`name` The name of the function or method that was executing when the frame was captured. - - :attr:`line` The text from the linecache module for the + - :attr:`line` The text from the linecache module for the line of code that was running when the frame was captured. - :attr:`locals` Either None if locals were not supplied, or a dict mapping the name to the repr() of the variable. From 27624a9cbf54849b521d4ba5f303cd6401ac084c Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:40:41 -0300 Subject: [PATCH 4/4] Avoid changing line unnecessarily. --- Lib/traceback.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 08e88aac55d566..ebddeb056359a7 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -293,8 +293,8 @@ class FrameSummary: active when the frame was captured. - :attr:`name` The name of the function or method that was executing when the frame was captured. - - :attr:`line` The text from the linecache module for the line of - code that was running when the frame was captured. + - :attr:`line` The text from the linecache module for the line + of code that was running when the frame was captured. - :attr:`locals` Either None if locals were not supplied, or a dict mapping the name to the repr() of the variable. - :attr:`end_lineno` The last line number of the source code for this frame.