Skip to content

Commit 99c8d16

Browse files
[3.11] gh-101100: Fix Sphinx nitpicks in library/traceback.rst (GH-113106) (#113112)
gh-101100: Fix Sphinx nitpicks in `library/traceback.rst` (GH-113106) (cherry picked from commit d9e1b57) Co-authored-by: Alex Waygood <[email protected]>
1 parent 3b7b256 commit 99c8d16

File tree

3 files changed

+75
-38
lines changed

3 files changed

+75
-38
lines changed

Doc/library/exceptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Exception context
4444
__suppress_context__ (exception attribute)
4545

4646
Three attributes on exception objects provide information about the context in
47-
which an the exception was raised:
47+
which the exception was raised:
4848

4949
.. attribute:: BaseException.__context__
5050
BaseException.__cause__

Doc/library/traceback.rst

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ interpreter.
1818

1919
The module uses :ref:`traceback objects <traceback-objects>` --- these are
2020
objects of type :class:`types.TracebackType`,
21-
which are assigned to the ``__traceback__`` field of :class:`BaseException` instances.
21+
which are assigned to the :attr:`~BaseException.__traceback__` field of
22+
:class:`BaseException` instances.
2223

2324
.. seealso::
2425

@@ -32,11 +33,13 @@ The module defines the following functions:
3233

3334
.. function:: print_tb(tb, limit=None, file=None)
3435

35-
Print up to *limit* stack trace entries from traceback object *tb* (starting
36+
Print up to *limit* stack trace entries from
37+
:ref:`traceback object <traceback-objects>` *tb* (starting
3638
from the caller's frame) if *limit* is positive. Otherwise, print the last
3739
``abs(limit)`` entries. If *limit* is omitted or ``None``, all entries are
3840
printed. If *file* is omitted or ``None``, the output goes to
39-
``sys.stderr``; otherwise it should be an open file or file-like object to
41+
:data:`sys.stderr`; otherwise it should be an open
42+
:term:`file <file object>` or :term:`file-like object` to
4043
receive the output.
4144

4245
.. versionchanged:: 3.5
@@ -46,7 +49,8 @@ The module defines the following functions:
4649
.. function:: print_exception(exc, /[, value, tb], limit=None, \
4750
file=None, chain=True)
4851

49-
Print exception information and stack trace entries from traceback object
52+
Print exception information and stack trace entries from
53+
:ref:`traceback object <traceback-objects>`
5054
*tb* to *file*. This differs from :func:`print_tb` in the following
5155
ways:
5256

@@ -99,7 +103,8 @@ The module defines the following functions:
99103
Print up to *limit* stack trace entries (starting from the invocation
100104
point) if *limit* is positive. Otherwise, print the last ``abs(limit)``
101105
entries. If *limit* is omitted or ``None``, all entries are printed.
102-
The optional *f* argument can be used to specify an alternate stack frame
106+
The optional *f* argument can be used to specify an alternate
107+
:ref:`stack frame <frame-objects>`
103108
to start. The optional *file* argument has the same meaning as for
104109
:func:`print_tb`.
105110

@@ -110,20 +115,20 @@ The module defines the following functions:
110115
.. function:: extract_tb(tb, limit=None)
111116

112117
Return a :class:`StackSummary` object representing a list of "pre-processed"
113-
stack trace entries extracted from the traceback object *tb*. It is useful
118+
stack trace entries extracted from the
119+
:ref:`traceback object <traceback-objects>` *tb*. It is useful
114120
for alternate formatting of stack traces. The optional *limit* argument has
115121
the same meaning as for :func:`print_tb`. A "pre-processed" stack trace
116122
entry is a :class:`FrameSummary` object containing attributes
117123
:attr:`~FrameSummary.filename`, :attr:`~FrameSummary.lineno`,
118124
:attr:`~FrameSummary.name`, and :attr:`~FrameSummary.line` representing the
119-
information that is usually printed for a stack trace. The
120-
:attr:`~FrameSummary.line` is a string with leading and trailing
121-
whitespace stripped; if the source is not available it is ``None``.
125+
information that is usually printed for a stack trace.
122126

123127

124128
.. function:: extract_stack(f=None, limit=None)
125129

126-
Extract the raw traceback from the current stack frame. The return value has
130+
Extract the raw traceback from the current
131+
:ref:`stack frame <frame-objects>`. The return value has
127132
the same format as for :func:`extract_tb`. The optional *f* and *limit*
128133
arguments have the same meaning as for :func:`print_stack`.
129134

@@ -141,7 +146,7 @@ The module defines the following functions:
141146
.. function:: format_exception_only(exc, /[, value])
142147

143148
Format the exception part of a traceback using an exception value such as
144-
given by ``sys.last_value``. The return value is a list of strings, each
149+
given by :data:`sys.last_value`. The return value is a list of strings, each
145150
ending in a newline. The list contains the exception's message, which is
146151
normally a single string; however, for :exc:`SyntaxError` exceptions, it
147152
contains several lines that (when printed) display detailed information
@@ -157,7 +162,8 @@ The module defines the following functions:
157162
positional-only.
158163

159164
.. versionchanged:: 3.11
160-
The returned list now includes any notes attached to the exception.
165+
The returned list now includes any
166+
:attr:`notes <BaseException.__notes__>` attached to the exception.
161167

162168

163169
.. function:: format_exception(exc, /[, value, tb], limit=None, chain=True)
@@ -193,14 +199,17 @@ The module defines the following functions:
193199

194200
.. function:: clear_frames(tb)
195201

196-
Clears the local variables of all the stack frames in a traceback *tb*
197-
by calling the :meth:`clear` method of each frame object.
202+
Clears the local variables of all the stack frames in a
203+
:ref:`traceback <traceback-objects>` *tb*
204+
by calling the :meth:`~frame.clear` method of each
205+
:ref:`frame object <frame-objects>`.
198206

199207
.. versionadded:: 3.4
200208

201209
.. function:: walk_stack(f)
202210

203-
Walk a stack following ``f.f_back`` from the given frame, yielding the frame
211+
Walk a stack following :attr:`f.f_back <frame.f_back>` from the given frame,
212+
yielding the frame
204213
and line number for each frame. If *f* is ``None``, the current stack is
205214
used. This helper is used with :meth:`StackSummary.extract`.
206215

@@ -216,12 +225,12 @@ The module defines the following functions:
216225

217226
The module also defines the following classes:
218227

219-
:class:`TracebackException` Objects
220-
-----------------------------------
228+
:class:`!TracebackException` Objects
229+
------------------------------------
221230

222231
.. versionadded:: 3.5
223232

224-
:class:`TracebackException` objects are created from actual exceptions to
233+
:class:`!TracebackException` objects are created from actual exceptions to
225234
capture data for later printing in a lightweight fashion.
226235

227236
.. class:: TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10)
@@ -361,42 +370,45 @@ capture data for later printing in a lightweight fashion.
361370
the syntax error occurred.
362371

363372
.. versionchanged:: 3.11
364-
The exception's notes are now included in the output.
373+
The exception's :attr:`notes <BaseException.__notes__>` are now
374+
included in the output.
365375

366376

367-
:class:`StackSummary` Objects
368-
-----------------------------
377+
:class:`!StackSummary` Objects
378+
------------------------------
369379

370380
.. versionadded:: 3.5
371381

372-
:class:`StackSummary` objects represent a call stack ready for formatting.
382+
:class:`!StackSummary` objects represent a call stack ready for formatting.
373383

374384
.. class:: StackSummary
375385

376386
.. classmethod:: extract(frame_gen, *, limit=None, lookup_lines=True, capture_locals=False)
377387

378-
Construct a :class:`StackSummary` object from a frame generator (such as
388+
Construct a :class:`!StackSummary` object from a frame generator (such as
379389
is returned by :func:`~traceback.walk_stack` or
380390
:func:`~traceback.walk_tb`).
381391

382392
If *limit* is supplied, only this many frames are taken from *frame_gen*.
383393
If *lookup_lines* is ``False``, the returned :class:`FrameSummary`
384394
objects will not have read their lines in yet, making the cost of
385-
creating the :class:`StackSummary` cheaper (which may be valuable if it
395+
creating the :class:`!StackSummary` cheaper (which may be valuable if it
386396
may not actually get formatted). If *capture_locals* is ``True`` the
387-
local variables in each :class:`FrameSummary` are captured as object
397+
local variables in each :class:`!FrameSummary` are captured as object
388398
representations.
389399

390400
.. classmethod:: from_list(a_list)
391401

392-
Construct a :class:`StackSummary` object from a supplied list of
402+
Construct a :class:`!StackSummary` object from a supplied list of
393403
:class:`FrameSummary` objects or old-style list of tuples. Each tuple
394-
should be a 4-tuple with filename, lineno, name, line as the elements.
404+
should be a 4-tuple with *filename*, *lineno*, *name*, *line* as the
405+
elements.
395406

396407
.. method:: format()
397408

398409
Returns a list of strings ready for printing. Each string in the
399-
resulting list corresponds to a single frame from the stack.
410+
resulting list corresponds to a single :ref:`frame <frame-objects>` from
411+
the stack.
400412
Each string ends in a newline; the strings may contain internal
401413
newlines as well, for those items with source text lines.
402414

@@ -409,33 +421,59 @@ capture data for later printing in a lightweight fashion.
409421

410422
.. method:: format_frame_summary(frame_summary)
411423

412-
Returns a string for printing one of the frames involved in the stack.
424+
Returns a string for printing one of the :ref:`frames <frame-objects>`
425+
involved in the stack.
413426
This method is called for each :class:`FrameSummary` object to be
414427
printed by :meth:`StackSummary.format`. If it returns ``None``, the
415428
frame is omitted from the output.
416429

417430
.. versionadded:: 3.11
418431

419432

420-
:class:`FrameSummary` Objects
421-
-----------------------------
433+
:class:`!FrameSummary` Objects
434+
------------------------------
422435

423436
.. versionadded:: 3.5
424437

425-
A :class:`FrameSummary` object represents a single frame in a traceback.
438+
A :class:`!FrameSummary` object represents a single :ref:`frame <frame-objects>`
439+
in a :ref:`traceback <traceback-objects>`.
426440

427441
.. class:: FrameSummary(filename, lineno, name, lookup_line=True, locals=None, line=None)
428442

429-
Represent a single frame in the traceback or stack that is being formatted
430-
or printed. It may optionally have a stringified version of the frames
443+
Represents a single :ref:`frame <frame-objects>` in the
444+
:ref:`traceback <traceback-objects>` or stack that is being formatted
445+
or printed. It may optionally have a stringified version of the frame's
431446
locals included in it. If *lookup_line* is ``False``, the source code is not
432-
looked up until the :class:`FrameSummary` has the :attr:`~FrameSummary.line`
433-
attribute accessed (which also happens when casting it to a tuple).
447+
looked up until the :class:`!FrameSummary` has the :attr:`~FrameSummary.line`
448+
attribute accessed (which also happens when casting it to a :class:`tuple`).
434449
:attr:`~FrameSummary.line` may be directly provided, and will prevent line
435450
lookups happening at all. *locals* is an optional local variable
436451
dictionary, and if supplied the variable representations are stored in the
437452
summary for later display.
438453

454+
:class:`!FrameSummary` instances have the following attributes:
455+
456+
.. attribute:: FrameSummary.filename
457+
458+
The filename of the source code for this frame. Equivalent to accessing
459+
:attr:`f.f_code.co_filename <codeobject.co_filename>` on a
460+
:ref:`frame object <frame-objects>` *f*.
461+
462+
.. attribute:: FrameSummary.lineno
463+
464+
The line number of the source code for this frame.
465+
466+
.. attribute:: FrameSummary.name
467+
468+
Equivalent to accessing :attr:`f.f_code.co_name <codeobject.co_name>` on
469+
a :ref:`frame object <frame-objects>` *f*.
470+
471+
.. attribute:: FrameSummary.line
472+
473+
A string representing the source code for this frame, with leading and
474+
trailing whitespace stripped.
475+
If the source is not available, it is ``None``.
476+
439477
.. _traceback-example:
440478

441479
Traceback Examples

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ Doc/library/test.rst
100100
Doc/library/tkinter.rst
101101
Doc/library/tkinter.scrolledtext.rst
102102
Doc/library/tkinter.ttk.rst
103-
Doc/library/traceback.rst
104103
Doc/library/unittest.mock.rst
105104
Doc/library/unittest.rst
106105
Doc/library/urllib.parse.rst

0 commit comments

Comments
 (0)