@@ -1227,8 +1227,9 @@ Frame objects
12271227
12281228.. index :: pair: object; frame
12291229
1230- Frame objects represent execution frames. They may occur in traceback objects
1231- (see below), and are also passed to registered trace functions.
1230+ Frame objects represent execution frames. They may occur in
1231+ :ref: `traceback objects <traceback-objects >`,
1232+ and are also passed to registered trace functions.
12321233
12331234.. index ::
12341235 single: f_back (frame attribute)
@@ -1335,26 +1336,30 @@ Traceback objects
13351336 single: sys.exception
13361337 single: sys.last_traceback
13371338
1338- Traceback objects represent a stack trace of an exception. A traceback object
1339+ Traceback objects represent the stack trace of an :ref: `exception <tut-errors >`.
1340+ A traceback object
13391341is implicitly created when an exception occurs, and may also be explicitly
13401342created by calling :class: `types.TracebackType `.
13411343
1344+ .. versionchanged :: 3.7
1345+ Traceback objects can now be explicitly instantiated from Python code.
1346+
13421347For implicitly created tracebacks, when the search for an exception handler
13431348unwinds the execution stack, at each unwound level a traceback object is
13441349inserted in front of the current traceback. When an exception handler is
13451350entered, the stack trace is made available to the program. (See section
13461351:ref: `try `.) It is accessible as the third item of the
1347- tuple returned by `` sys.exc_info() ` `, and as the ``__traceback__ `` attribute
1352+ tuple returned by :func: ` sys.exc_info `, and as the ``__traceback__ `` attribute
13481353of the caught exception.
13491354
13501355When the program contains no suitable
13511356handler, the stack trace is written (nicely formatted) to the standard error
13521357stream; if the interpreter is interactive, it is also made available to the user
1353- as `` sys.last_traceback ` `.
1358+ as :data: ` sys.last_traceback `.
13541359
13551360For explicitly created tracebacks, it is up to the creator of the traceback
1356- to determine how the `` tb_next `` attributes should be linked to form a
1357- full stack trace.
1361+ to determine how the :attr: ` ~traceback. tb_next ` attributes should be linked to
1362+ form a full stack trace.
13581363
13591364.. index ::
13601365 single: tb_frame (traceback attribute)
@@ -1363,27 +1368,40 @@ full stack trace.
13631368 pair: statement; try
13641369
13651370Special read-only attributes:
1366- :attr: `tb_frame ` points to the execution frame of the current level;
1367- :attr: `tb_lineno ` gives the line number where the exception occurred;
1368- :attr: `tb_lasti ` indicates the precise instruction.
1371+
1372+ .. list-table ::
1373+
1374+ * - .. attribute:: traceback.tb_frame
1375+ - Points to the execution :ref: `frame <frame-objects >` of the current
1376+ level.
1377+
1378+ Accessing this attribute raises an
1379+ :ref: `auditing event <auditing >` ``object.__getattr__ `` with arguments
1380+ ``obj `` and ``"tb_frame" ``.
1381+
1382+ * - .. attribute:: traceback.tb_lineno
1383+ - Gives the line number where the exception occurred
1384+
1385+ * - .. attribute:: traceback.tb_lasti
1386+ - Indicates the "precise instruction".
1387+
13691388The line number and last instruction in the traceback may differ from the
1370- line number of its frame object if the exception occurred in a
1389+ line number of its :ref: `frame object <frame-objects >` if the exception
1390+ occurred in a
13711391:keyword: `try ` statement with no matching except clause or with a
1372- finally clause.
1373-
1374- Accessing ``tb_frame `` raises an :ref: `auditing event <auditing >`
1375- ``object.__getattr__ `` with arguments ``obj `` and ``"tb_frame" ``.
1392+ :keyword: `finally ` clause.
13761393
13771394.. index ::
13781395 single: tb_next (traceback attribute)
13791396
1380- Special writable attribute: :attr: `tb_next ` is the next level in the stack
1381- trace (towards the frame where the exception occurred), or ``None `` if
1382- there is no next level.
1397+ .. attribute :: traceback.tb_next
13831398
1384- .. versionchanged :: 3.7
1385- Traceback objects can now be explicitly instantiated from Python code,
1386- and the ``tb_next `` attribute of existing instances can be updated.
1399+ The special writable attribute :attr: `!tb_next ` is the next level in the
1400+ stack trace (towards the frame where the exception occurred), or ``None `` if
1401+ there is no next level.
1402+
1403+ .. versionchanged :: 3.7
1404+ This attribute is now writable
13871405
13881406
13891407Slice objects
0 commit comments