Skip to content

Commit f394ee5

Browse files
torsavaberkerpeksag
andcommitted
bpo-27910: Update documentation of traceback module (GH-6116)
In the documentation for the traceback module, the definitions of functions extract_tb(), format_list() and classmethod StackSummary.from_list() mention the old style 4-tuples that these functions used to return or accept. Since Python 3.5, however, they return or accept a FrameSummary object instead of a 4-tuple, or a StackSummary object instead of a list of 4-tuples. Co-Authored-By: Berker Peksag <berker.peksag@gmail.com>
1 parent a2fe1e5 commit f394ee5

2 files changed

Lines changed: 35 additions & 30 deletions

File tree

Doc/library/traceback.rst

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ The module defines the following functions:
8888

8989
.. function:: extract_tb(tb, limit=None)
9090

91-
Return a list of "pre-processed" stack trace entries extracted from the
92-
traceback object *tb*. It is useful for alternate formatting of
93-
stack traces. The optional *limit* argument has the same meaning as for
94-
:func:`print_tb`. A "pre-processed" stack trace entry is a 4-tuple
95-
(*filename*, *line number*, *function name*, *text*) representing the
96-
information that is usually printed for a stack trace. The *text* is a
97-
string with leading and trailing whitespace stripped; if the source is
98-
not available it is ``None``.
91+
Return a :class:`StackSummary` object representing a list of "pre-processed"
92+
stack trace entries extracted from the traceback object *tb*. It is useful
93+
for alternate formatting of stack traces. The optional *limit* argument has
94+
the same meaning as for :func:`print_tb`. A "pre-processed" stack trace
95+
entry is a :class:`FrameSummary` object containing attributes
96+
:attr:`~FrameSummary.filename`, :attr:`~FrameSummary.lineno`,
97+
:attr:`~FrameSummary.name`, and :attr:`~FrameSummary.line` representing the
98+
information that is usually printed for a stack trace. The
99+
:attr:`~FrameSummary.line` is a string with leading and trailing
100+
whitespace stripped; if the source is not available it is ``None``.
99101

100102

101103
.. function:: extract_stack(f=None, limit=None)
@@ -107,12 +109,12 @@ The module defines the following functions:
107109

108110
.. function:: format_list(extracted_list)
109111

110-
Given a list of tuples as returned by :func:`extract_tb` or
111-
:func:`extract_stack`, return a list of strings ready for printing. Each
112-
string in the resulting list corresponds to the item with the same index in
113-
the argument list. Each string ends in a newline; the strings may contain
114-
internal newlines as well, for those items whose source text line is not
115-
``None``.
112+
Given a list of tuples or :class:`FrameSummary` objects as returned by
113+
:func:`extract_tb` or :func:`extract_stack`, return a list of strings ready
114+
for printing. Each string in the resulting list corresponds to the item with
115+
the same index in the argument list. Each string ends in a newline; the
116+
strings may contain internal newlines as well, for those items whose source
117+
text line is not ``None``.
116118

117119

118120
.. function:: format_exception_only(etype, value)
@@ -293,9 +295,9 @@ capture data for later printing in a lightweight fashion.
293295

294296
.. classmethod:: from_list(a_list)
295297

296-
Construct a :class:`StackSummary` object from a supplied old-style list
297-
of tuples. Each tuple should be a 4-tuple with filename, lineno, name,
298-
line as the elements.
298+
Construct a :class:`StackSummary` object from a supplied list of
299+
:class:`FrameSummary` objects or old-style list of tuples. Each tuple
300+
should be a 4-tuple with filename, lineno, name, line as the elements.
299301

300302
.. method:: format()
301303

Lib/traceback.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ def print_list(extracted_list, file=None):
2525
print(item, file=file, end="")
2626

2727
def format_list(extracted_list):
28-
"""Format a list of traceback entry tuples for printing.
28+
"""Format a list of tuples or FrameSummary objects for printing.
29+
30+
Given a list of tuples or FrameSummary objects as returned by
31+
extract_tb() or extract_stack(), return a list of strings ready
32+
for printing.
2933
30-
Given a list of tuples as returned by extract_tb() or
31-
extract_stack(), return a list of strings ready for printing.
3234
Each string in the resulting list corresponds to the item with the
3335
same index in the argument list. Each string ends in a newline;
3436
the strings may contain internal newlines as well, for those items
@@ -55,15 +57,17 @@ def format_tb(tb, limit=None):
5557
return extract_tb(tb, limit=limit).format()
5658

5759
def extract_tb(tb, limit=None):
58-
"""Return list of up to limit pre-processed entries from traceback.
60+
"""
61+
Return a StackSummary object representing a list of
62+
pre-processed entries from traceback.
5963
6064
This is useful for alternate formatting of stack traces. If
6165
'limit' is omitted or None, all entries are extracted. A
62-
pre-processed stack trace entry is a quadruple (filename, line
63-
number, function name, text) representing the information that is
64-
usually printed for a stack trace. The text is a string with
65-
leading and trailing whitespace stripped; if the source is not
66-
available it is None.
66+
pre-processed stack trace entry is a FrameSummary object
67+
containing attributes filename, lineno, name, and line
68+
representing the information that is usually printed for a stack
69+
trace. The line is a string with leading and trailing
70+
whitespace stripped; if the source is not available it is None.
6771
"""
6872
return StackSummary.extract(walk_tb(tb), limit=limit)
6973

@@ -359,10 +363,9 @@ def extract(klass, frame_gen, *, limit=None, lookup_lines=True,
359363

360364
@classmethod
361365
def from_list(klass, a_list):
362-
"""Create a StackSummary from a simple list of tuples.
363-
364-
This method supports the older Python API. Each tuple should be a
365-
4-tuple with (filename, lineno, name, line) elements.
366+
"""
367+
Create a StackSummary object from a supplied list of
368+
FrameSummary objects or old-style list of tuples.
366369
"""
367370
# While doing a fast-path check for isinstance(a_list, StackSummary) is
368371
# appealing, idlelib.run.cleanup_traceback and other similar code may

0 commit comments

Comments
 (0)