@@ -1163,17 +1163,85 @@ Classes and functions
11631163The interpreter stack
11641164---------------------
11651165
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.
11731205
11741206.. versionchanged :: 3.5
11751207 Return a named tuple instead of a tuple.
11761208
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+
11771245.. note ::
11781246
11791247 Keeping references to frame objects, as found in the first element of the frame
@@ -1207,35 +1275,41 @@ line.
12071275
12081276.. function :: getframeinfo(frame, context=1)
12091277
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.
12121280
1281+ .. versionchanged :: 3.11
1282+ A :class: `Traceback ` object is returned instead of a named tuple.
12131283
12141284.. function :: getouterframes(frame, context=1)
12151285
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.
12201290
12211291 .. versionchanged :: 3.5
12221292 A list of :term: `named tuples <named tuple> `
12231293 ``FrameInfo(frame, filename, lineno, function, code_context, index) ``
12241294 is returned.
12251295
1296+ .. versionchanged :: 3.11
1297+ A list of :class: `FrameInfo ` objects is returned.
12261298
12271299.. function :: getinnerframes(traceback, context=1)
12281300
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.
12331305
12341306 .. versionchanged :: 3.5
12351307 A list of :term: `named tuples <named tuple> `
12361308 ``FrameInfo(frame, filename, lineno, function, code_context, index) ``
12371309 is returned.
12381310
1311+ .. versionchanged :: 3.11
1312+ A list of :class: `FrameInfo ` objects is returned.
12391313
12401314.. function :: currentframe()
12411315
@@ -1251,28 +1325,32 @@ line.
12511325
12521326.. function :: stack(context=1)
12531327
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.
12571331
12581332 .. versionchanged :: 3.5
12591333 A list of :term: `named tuples <named tuple> `
12601334 ``FrameInfo(frame, filename, lineno, function, code_context, index) ``
12611335 is returned.
12621336
1337+ .. versionchanged :: 3.11
1338+ A list of :class: `FrameInfo ` objects is returned.
12631339
12641340.. function :: trace(context=1)
12651341
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.
12701346
12711347 .. versionchanged :: 3.5
12721348 A list of :term: `named tuples <named tuple> `
12731349 ``FrameInfo(frame, filename, lineno, function, code_context, index) ``
12741350 is returned.
12751351
1352+ .. versionchanged :: 3.11
1353+ A list of :class: `FrameInfo ` objects is returned.
12761354
12771355Fetching attributes statically
12781356------------------------------
0 commit comments