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