@@ -1174,47 +1174,81 @@ Frame objects represent execution frames. They may occur in traceback objects
1174
1174
single: f_lasti (frame attribute)
1175
1175
single: f_builtins (frame attribute)
1176
1176
1177
- Special read-only attributes: :attr: `f_back ` is to the previous stack frame
1178
- (towards the caller), or ``None `` if this is the bottom stack frame;
1179
- :attr: `f_code ` is the code object being executed in this frame; :attr: `f_locals `
1180
- is the dictionary used to look up local variables; :attr: `f_globals ` is used for
1181
- global variables; :attr: `f_builtins ` is used for built-in (intrinsic) names;
1182
- :attr: `f_lasti ` gives the precise instruction (this is an index into the
1183
- bytecode string of the code object).
1177
+ Special read-only attributes
1178
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1184
1179
1185
- Accessing ``f_code `` raises an :ref: `auditing event <auditing >`
1186
- ``object.__getattr__ `` with arguments ``obj `` and ``"f_code" ``.
1180
+ .. list-table ::
1181
+
1182
+ * - .. attribute:: frame.f_back
1183
+ - Points to the previous stack frame (towards the caller),
1184
+ or ``None `` if this is the bottom stack frame
1185
+
1186
+ * - .. attribute:: frame.f_code
1187
+ - The :ref: `code object <code-objects >` being executed in this frame.
1188
+ Accessing this attribute raises an :ref: `auditing event <auditing >`
1189
+ ``object.__getattr__ `` with arguments ``obj `` and ``"f_code" ``.
1190
+
1191
+ * - .. attribute:: frame.f_locals
1192
+ - The dictionary used by the frame to look up
1193
+ :ref: `local variables <naming >`
1194
+
1195
+ * - .. attribute:: frame.f_globals
1196
+ - The dictionary used by the frame to look up
1197
+ :ref: `global variables <naming >`
1198
+
1199
+ * - .. attribute:: frame.f_builtins
1200
+ - The dictionary used by the frame to look up
1201
+ :ref: `built-in (intrinsic) names <naming >`
1202
+
1203
+ * - .. attribute:: frame.f_lasti
1204
+ - The "precise instruction" of the frame object
1205
+ (this is an index into the :term: `bytecode ` string of the
1206
+ :ref: `code object <code-objects >`)
1187
1207
1188
1208
.. index ::
1189
1209
single: f_trace (frame attribute)
1190
1210
single: f_trace_lines (frame attribute)
1191
1211
single: f_trace_opcodes (frame attribute)
1192
1212
single: f_lineno (frame attribute)
1193
1213
1194
- Special writable attributes: :attr: `f_trace `, if not ``None ``, is a function
1195
- called for various events during code execution (this is used by the debugger).
1196
- Normally an event is triggered for each new source line - this can be
1197
- disabled by setting :attr: `f_trace_lines ` to :const: `False `.
1214
+ Special writable attributes
1215
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1216
+
1217
+ .. list-table ::
1218
+
1219
+ * - .. attribute:: frame.f_trace
1220
+ - If not ``None ``, this is a function called for various events during
1221
+ code execution (this is used by debuggers). Normally an event is
1222
+ triggered for each new source line (see :attr: `~frame.f_trace_lines `).
1223
+
1224
+ * - .. attribute:: frame.f_trace_lines
1225
+ - Set this attribute to :const: `False ` to disable triggering a tracing
1226
+ event for each source line.
1227
+
1228
+ * - .. attribute:: frame.f_trace_opcodes
1229
+ - Set this attribute to :const: `True ` to allow per-opcode events to be
1230
+ requested. Note that this may lead to
1231
+ undefined interpreter behaviour if exceptions raised by the trace
1232
+ function escape to the function being traced.
1198
1233
1199
- Implementations *may * allow per-opcode events to be requested by setting
1200
- :attr: `f_trace_opcodes ` to :const: `True `. Note that this may lead to
1201
- undefined interpreter behaviour if exceptions raised by the trace
1202
- function escape to the function being traced.
1234
+ * - .. attribute:: frame.f_lineno
1235
+ - The current line number of the frame -- writing to this
1236
+ from within a trace function jumps to the given line (only for the bottom-most
1237
+ frame). A debugger can implement a Jump command (aka Set Next Statement)
1238
+ by writing to this attribute.
1203
1239
1204
- :attr: `f_lineno ` is the current line number of the frame --- writing to this
1205
- from within a trace function jumps to the given line (only for the bottom-most
1206
- frame). A debugger can implement a Jump command (aka Set Next Statement)
1207
- by writing to f_lineno.
1240
+ Frame object methods
1241
+ ~~~~~~~~~~~~~~~~~~~~
1208
1242
1209
1243
Frame objects support one method:
1210
1244
1211
1245
.. method :: frame.clear()
1212
1246
1213
- This method clears all references to local variables held by the
1214
- frame. Also, if the frame belonged to a generator, the generator
1247
+ This method clears all references to :ref: ` local variables < naming >` held by the
1248
+ frame. Also, if the frame belonged to a :term: ` generator ` , the generator
1215
1249
is finalized. This helps break reference cycles involving frame
1216
- objects (for example when catching an exception and storing its
1217
- traceback for later use).
1250
+ objects (for example when catching an :ref: ` exception < bltin-exceptions >`
1251
+ and storing its :ref: ` traceback < traceback-objects >` for later use).
1218
1252
1219
1253
:exc: `RuntimeError ` is raised if the frame is currently executing
1220
1254
or suspended.
0 commit comments