@@ -1244,8 +1244,9 @@ Frame objects
1244
1244
1245
1245
.. index :: pair: object; frame
1246
1246
1247
- Frame objects represent execution frames. They may occur in traceback objects
1248
- (see below), and are also passed to registered trace functions.
1247
+ Frame objects represent execution frames. They may occur in
1248
+ :ref: `traceback objects <traceback-objects >`,
1249
+ and are also passed to registered trace functions.
1249
1250
1250
1251
.. index ::
1251
1252
single: f_back (frame attribute)
@@ -1352,26 +1353,30 @@ Traceback objects
1352
1353
single: sys.exception
1353
1354
single: sys.last_traceback
1354
1355
1355
- Traceback objects represent a stack trace of an exception. A traceback object
1356
+ Traceback objects represent the stack trace of an :ref: `exception <tut-errors >`.
1357
+ A traceback object
1356
1358
is implicitly created when an exception occurs, and may also be explicitly
1357
1359
created by calling :class: `types.TracebackType `.
1358
1360
1361
+ .. versionchanged :: 3.7
1362
+ Traceback objects can now be explicitly instantiated from Python code.
1363
+
1359
1364
For implicitly created tracebacks, when the search for an exception handler
1360
1365
unwinds the execution stack, at each unwound level a traceback object is
1361
1366
inserted in front of the current traceback. When an exception handler is
1362
1367
entered, the stack trace is made available to the program. (See section
1363
1368
:ref: `try `.) It is accessible as the third item of the
1364
- tuple returned by `` sys.exc_info() ` `, and as the ``__traceback__ `` attribute
1369
+ tuple returned by :func: ` sys.exc_info `, and as the ``__traceback__ `` attribute
1365
1370
of the caught exception.
1366
1371
1367
1372
When the program contains no suitable
1368
1373
handler, the stack trace is written (nicely formatted) to the standard error
1369
1374
stream; if the interpreter is interactive, it is also made available to the user
1370
- as `` sys.last_traceback ` `.
1375
+ as :data: ` sys.last_traceback `.
1371
1376
1372
1377
For explicitly created tracebacks, it is up to the creator of the traceback
1373
- to determine how the `` tb_next `` attributes should be linked to form a
1374
- full stack trace.
1378
+ to determine how the :attr: ` ~traceback. tb_next ` attributes should be linked to
1379
+ form a full stack trace.
1375
1380
1376
1381
.. index ::
1377
1382
single: tb_frame (traceback attribute)
@@ -1380,27 +1385,40 @@ full stack trace.
1380
1385
pair: statement; try
1381
1386
1382
1387
Special read-only attributes:
1383
- :attr: `tb_frame ` points to the execution frame of the current level;
1384
- :attr: `tb_lineno ` gives the line number where the exception occurred;
1385
- :attr: `tb_lasti ` indicates the precise instruction.
1388
+
1389
+ .. list-table ::
1390
+
1391
+ * - .. attribute:: traceback.tb_frame
1392
+ - Points to the execution :ref: `frame <frame-objects >` of the current
1393
+ level.
1394
+
1395
+ Accessing this attribute raises an
1396
+ :ref: `auditing event <auditing >` ``object.__getattr__ `` with arguments
1397
+ ``obj `` and ``"tb_frame" ``.
1398
+
1399
+ * - .. attribute:: traceback.tb_lineno
1400
+ - Gives the line number where the exception occurred
1401
+
1402
+ * - .. attribute:: traceback.tb_lasti
1403
+ - Indicates the "precise instruction".
1404
+
1386
1405
The line number and last instruction in the traceback may differ from the
1387
- line number of its frame object if the exception occurred in a
1406
+ line number of its :ref: `frame object <frame-objects >` if the exception
1407
+ occurred in a
1388
1408
:keyword: `try ` statement with no matching except clause or with a
1389
- finally clause.
1390
-
1391
- Accessing ``tb_frame `` raises an :ref: `auditing event <auditing >`
1392
- ``object.__getattr__ `` with arguments ``obj `` and ``"tb_frame" ``.
1409
+ :keyword: `finally ` clause.
1393
1410
1394
1411
.. index ::
1395
1412
single: tb_next (traceback attribute)
1396
1413
1397
- Special writable attribute: :attr: `tb_next ` is the next level in the stack
1398
- trace (towards the frame where the exception occurred), or ``None `` if
1399
- there is no next level.
1414
+ .. attribute :: traceback.tb_next
1400
1415
1401
- .. versionchanged :: 3.7
1402
- Traceback objects can now be explicitly instantiated from Python code,
1403
- and the ``tb_next `` attribute of existing instances can be updated.
1416
+ The special writable attribute :attr: `!tb_next ` is the next level in the
1417
+ stack trace (towards the frame where the exception occurred), or ``None `` if
1418
+ there is no next level.
1419
+
1420
+ .. versionchanged :: 3.7
1421
+ This attribute is now writable
1404
1422
1405
1423
1406
1424
Slice objects
0 commit comments