@@ -1163,17 +1163,85 @@ Classes and functions
1163
1163
The interpreter stack
1164
1164
---------------------
1165
1165
1166
- When the following functions return "frame records," each record is a
1167
- :term: `named tuple `
1168
- ``FrameInfo(frame, filename, lineno, function, code_context, index) ``.
1169
- The tuple contains the frame object, the filename, the line number of the
1170
- current line,
1171
- the function name, a list of lines of context from the source code, and the
1172
- index of the current line within that list.
1166
+ Some of the following functions return
1167
+ :class: `FrameInfo ` objects. For backwards compatibility these objects allow
1168
+ tuple-like operations on all attributes except ``positions ``. This behavior
1169
+ is considered deprecated and may be removed in the future.
1170
+
1171
+ .. class :: FrameInfo
1172
+
1173
+ .. attribute :: frame
1174
+
1175
+ The :ref: `frame object <frame-objects >` that the record corresponds to.
1176
+
1177
+ .. attribute :: filename
1178
+
1179
+ The file name associated with the code being executed by the frame this record
1180
+ corresponds to.
1181
+
1182
+ .. attribute :: lineno
1183
+
1184
+ The line number of the current line associated with the code being
1185
+ executed by the frame this record corresponds to.
1186
+
1187
+ .. attribute :: function
1188
+
1189
+ The function name that is being executed by the frame this record corresponds to.
1190
+
1191
+ .. attribute :: code_context
1192
+
1193
+ A list of lines of context from the source code that's being executed by the frame
1194
+ this record corresponds to.
1195
+
1196
+ .. attribute :: index
1197
+
1198
+ The index of the current line being executed in the :attr: `code_context ` list.
1199
+
1200
+ .. attribute :: positions
1201
+
1202
+ A :class: `dis.Positions ` object containing the start line number, end line
1203
+ number, start column offset, and end column offset associated with the
1204
+ instruction being executed by the frame this record corresponds to.
1173
1205
1174
1206
.. versionchanged :: 3.5
1175
1207
Return a named tuple instead of a tuple.
1176
1208
1209
+ .. versionchanged :: 3.11
1210
+ Changed the return object from a named tuple to a regular object (that is
1211
+ backwards compatible with the previous named tuple).
1212
+
1213
+ .. class :: Traceback
1214
+
1215
+ .. attribute :: filename
1216
+
1217
+ The file name associated with the code being executed by the frame this traceback
1218
+ corresponds to.
1219
+
1220
+ .. attribute :: lineno
1221
+
1222
+ The line number of the current line associated with the code being
1223
+ executed by the frame this traceback corresponds to.
1224
+
1225
+ .. attribute :: function
1226
+
1227
+ The function name that is being executed by the frame this traceback corresponds to.
1228
+
1229
+ .. attribute :: code_context
1230
+
1231
+ A list of lines of context from the source code that's being executed by the frame
1232
+ this traceback corresponds to.
1233
+
1234
+ .. attribute :: index
1235
+
1236
+ The index of the current line being executed in the :attr: `code_context ` list.
1237
+
1238
+ .. attribute :: positions
1239
+
1240
+ A :class: `dis.Positions ` object containing the start line number, end
1241
+ line number, start column offset, and end column offset associated with
1242
+ the instruction being executed by the frame this traceback corresponds
1243
+ to.
1244
+
1177
1245
.. note ::
1178
1246
1179
1247
Keeping references to frame objects, as found in the first element of the frame
@@ -1207,35 +1275,41 @@ line.
1207
1275
1208
1276
.. function :: getframeinfo(frame, context=1)
1209
1277
1210
- Get information about a frame or traceback object. A :term: ` named tuple `
1211
- `` Traceback(filename, lineno, function, code_context, index) `` is returned.
1278
+ Get information about a frame or traceback object. A :class: ` Traceback ` object
1279
+ is returned.
1212
1280
1281
+ .. versionchanged :: 3.11
1282
+ A :class: `Traceback ` object is returned instead of a named tuple.
1213
1283
1214
1284
.. function :: getouterframes(frame, context=1)
1215
1285
1216
- Get a list of frame records for a frame and all outer frames. These frames
1217
- represent the calls that lead to the creation of *frame *. The first entry in the
1218
- returned list represents *frame *; the last entry represents the outermost call
1219
- on *frame *'s stack.
1286
+ Get a list of :class: ` FrameInfo ` objects for a frame and all outer frames.
1287
+ These frames represent the calls that lead to the creation of *frame *. The
1288
+ first entry in the returned list represents *frame *; the last entry
1289
+ represents the outermost call on *frame *'s stack.
1220
1290
1221
1291
.. versionchanged :: 3.5
1222
1292
A list of :term: `named tuples <named tuple> `
1223
1293
``FrameInfo(frame, filename, lineno, function, code_context, index) ``
1224
1294
is returned.
1225
1295
1296
+ .. versionchanged :: 3.11
1297
+ A list of :class: `FrameInfo ` objects is returned.
1226
1298
1227
1299
.. function :: getinnerframes(traceback, context=1)
1228
1300
1229
- Get a list of frame records for a traceback's frame and all inner frames. These
1230
- frames represent calls made as a consequence of *frame *. The first entry in the
1231
- list represents *traceback *; the last entry represents where the exception was
1232
- raised.
1301
+ Get a list of :class: ` FrameInfo ` objects for a traceback's frame and all
1302
+ inner frames. These frames represent calls made as a consequence of *frame *.
1303
+ The first entry in the list represents *traceback *; the last entry represents
1304
+ where the exception was raised.
1233
1305
1234
1306
.. versionchanged :: 3.5
1235
1307
A list of :term: `named tuples <named tuple> `
1236
1308
``FrameInfo(frame, filename, lineno, function, code_context, index) ``
1237
1309
is returned.
1238
1310
1311
+ .. versionchanged :: 3.11
1312
+ A list of :class: `FrameInfo ` objects is returned.
1239
1313
1240
1314
.. function :: currentframe()
1241
1315
@@ -1251,28 +1325,32 @@ line.
1251
1325
1252
1326
.. function :: stack(context=1)
1253
1327
1254
- Return a list of frame records for the caller's stack. The first entry in the
1255
- returned list represents the caller; the last entry represents the outermost
1256
- call on the stack.
1328
+ Return a list of :class: ` FrameInfo ` objects for the caller's stack. The
1329
+ first entry in the returned list represents the caller; the last entry
1330
+ represents the outermost call on the stack.
1257
1331
1258
1332
.. versionchanged :: 3.5
1259
1333
A list of :term: `named tuples <named tuple> `
1260
1334
``FrameInfo(frame, filename, lineno, function, code_context, index) ``
1261
1335
is returned.
1262
1336
1337
+ .. versionchanged :: 3.11
1338
+ A list of :class: `FrameInfo ` objects is returned.
1263
1339
1264
1340
.. function :: trace(context=1)
1265
1341
1266
- Return a list of frame records for the stack between the current frame and the
1267
- frame in which an exception currently being handled was raised in. The first
1268
- entry in the list represents the caller; the last entry represents where the
1269
- exception was raised.
1342
+ Return a list of :class: ` FrameInfo ` objects for the stack between the current
1343
+ frame and the frame in which an exception currently being handled was raised
1344
+ in. The first entry in the list represents the caller; the last entry
1345
+ represents where the exception was raised.
1270
1346
1271
1347
.. versionchanged :: 3.5
1272
1348
A list of :term: `named tuples <named tuple> `
1273
1349
``FrameInfo(frame, filename, lineno, function, code_context, index) ``
1274
1350
is returned.
1275
1351
1352
+ .. versionchanged :: 3.11
1353
+ A list of :class: `FrameInfo ` objects is returned.
1276
1354
1277
1355
Fetching attributes statically
1278
1356
------------------------------
0 commit comments