Skip to content

Commit c6c559a

Browse files
[3.12] gh-101100: Fix Sphinx nitpicks in library/traceback.rst (GH-113106) (#113111)
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 dc568dd commit c6c559a

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

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

@@ -109,20 +114,20 @@ The module defines the following functions:
109114
.. function:: extract_tb(tb, limit=None)
110115

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

122126

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

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

@@ -140,7 +145,7 @@ The module defines the following functions:
140145
.. function:: format_exception_only(exc, /[, value])
141146

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

158163
.. versionchanged:: 3.11
159-
The returned list now includes any notes attached to the exception.
164+
The returned list now includes any
165+
:attr:`notes <BaseException.__notes__>` attached to the exception.
160166

161167

162168
.. function:: format_exception(exc, /[, value, tb], limit=None, chain=True)
@@ -192,14 +198,17 @@ The module defines the following functions:
192198

193199
.. function:: clear_frames(tb)
194200

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

198206
.. versionadded:: 3.4
199207

200208
.. function:: walk_stack(f)
201209

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

@@ -215,12 +224,12 @@ The module defines the following functions:
215224

216225
The module also defines the following classes:
217226

218-
:class:`TracebackException` Objects
219-
-----------------------------------
227+
:class:`!TracebackException` Objects
228+
------------------------------------
220229

221230
.. versionadded:: 3.5
222231

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

226235
.. 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)
@@ -360,31 +369,32 @@ capture data for later printing in a lightweight fashion.
360369
the syntax error occurred.
361370

362371
.. versionchanged:: 3.11
363-
The exception's notes are now included in the output.
372+
The exception's :attr:`notes <BaseException.__notes__>` are now
373+
included in the output.
364374

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
.. versionchanged:: 3.12
@@ -393,14 +403,16 @@ capture data for later printing in a lightweight fashion.
393403

394404
.. classmethod:: from_list(a_list)
395405

396-
Construct a :class:`StackSummary` object from a supplied list of
406+
Construct a :class:`!StackSummary` object from a supplied list of
397407
:class:`FrameSummary` objects or old-style list of tuples. Each tuple
398-
should be a 4-tuple with filename, lineno, name, line as the elements.
408+
should be a 4-tuple with *filename*, *lineno*, *name*, *line* as the
409+
elements.
399410

400411
.. method:: format()
401412

402413
Returns a list of strings ready for printing. Each string in the
403-
resulting list corresponds to a single frame from the stack.
414+
resulting list corresponds to a single :ref:`frame <frame-objects>` from
415+
the stack.
404416
Each string ends in a newline; the strings may contain internal
405417
newlines as well, for those items with source text lines.
406418

@@ -413,33 +425,59 @@ capture data for later printing in a lightweight fashion.
413425

414426
.. method:: format_frame_summary(frame_summary)
415427

416-
Returns a string for printing one of the frames involved in the stack.
428+
Returns a string for printing one of the :ref:`frames <frame-objects>`
429+
involved in the stack.
417430
This method is called for each :class:`FrameSummary` object to be
418431
printed by :meth:`StackSummary.format`. If it returns ``None``, the
419432
frame is omitted from the output.
420433

421434
.. versionadded:: 3.11
422435

423436

424-
:class:`FrameSummary` Objects
425-
-----------------------------
437+
:class:`!FrameSummary` Objects
438+
------------------------------
426439

427440
.. versionadded:: 3.5
428441

429-
A :class:`FrameSummary` object represents a single frame in a traceback.
442+
A :class:`!FrameSummary` object represents a single :ref:`frame <frame-objects>`
443+
in a :ref:`traceback <traceback-objects>`.
430444

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

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

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

445483
Traceback Examples

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ Doc/library/tkinter.rst
111111
Doc/library/tkinter.scrolledtext.rst
112112
Doc/library/tkinter.tix.rst
113113
Doc/library/tkinter.ttk.rst
114-
Doc/library/traceback.rst
115114
Doc/library/unittest.mock.rst
116115
Doc/library/unittest.rst
117116
Doc/library/urllib.parse.rst

0 commit comments

Comments
 (0)