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