| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,7 @@ See also :ref:`Reflection <reflection>`. | |||
| 50 | 50 | ||
| 51 | 51 | .. c:function:: PyObject* PyFrame_GetBuiltins(PyFrameObject *frame) | |
| 52 | 52 | ||
| 53 | - Get the *frame*'s ``f_builtins`` attribute. | ||
| 53 | + Get the *frame*'s :attr:`~frame.f_builtins` attribute. | ||
| 54 | 54 | ||
| 55 | 55 | Return a :term:`strong reference`. The result cannot be ``NULL``. | |
| 56 | 56 | ||
@@ -81,7 +81,7 @@ See also :ref:`Reflection <reflection>`. | |||
| 81 | 81 | ||
| 82 | 82 | .. c:function:: PyObject* PyFrame_GetGlobals(PyFrameObject *frame) | |
| 83 | 83 | ||
| 84 | - Get the *frame*'s ``f_globals`` attribute. | ||
| 84 | + Get the *frame*'s :attr:`~frame.f_globals` attribute. | ||
| 85 | 85 | ||
| 86 | 86 | Return a :term:`strong reference`. The result cannot be ``NULL``. | |
| 87 | 87 | ||
@@ -90,7 +90,7 @@ See also :ref:`Reflection <reflection>`. | |||
| 90 | 90 | ||
| 91 | 91 | .. c:function:: int PyFrame_GetLasti(PyFrameObject *frame) | |
| 92 | 92 | ||
| 93 | - Get the *frame*'s ``f_lasti`` attribute. | ||
| 93 | + Get the *frame*'s :attr:`~frame.f_lasti` attribute. | ||
| 94 | 94 | ||
| 95 | 95 | Returns -1 if ``frame.f_lasti`` is ``None``. | |
| 96 | 96 | ||
@@ -99,7 +99,7 @@ See also :ref:`Reflection <reflection>`. | |||
| 99 | 99 | ||
| 100 | 100 | .. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame) | |
| 101 | 101 | ||
| 102 | - Get the *frame*'s ``f_locals`` attribute (:class:`dict`). | ||
| 102 | + Get the *frame*'s :attr:`~frame.f_locals` attribute (:class:`dict`). | ||
| 103 | 103 | ||
| 104 | 104 | Return a :term:`strong reference`. | |
| 105 | 105 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1620,7 +1620,8 @@ Python-level trace functions in previous versions. | |||
| 1620 | 1620 | ||
| 1621 | 1621 | The value passed as the *what* parameter to a :c:type:`Py_tracefunc` function | |
| 1622 | 1622 | (but not a profiling function) when a line-number event is being reported. | |
| 1623 | - It may be disabled for a frame by setting :attr:`f_trace_lines` to *0* on that frame. | ||
| 1623 | + It may be disabled for a frame by setting :attr:`~frame.f_trace_lines` to | ||
| 1624 | + *0* on that frame. | ||
| 1624 | 1625 | ||
| 1625 | 1626 | ||
| 1626 | 1627 | .. c:var:: int PyTrace_RETURN | |
@@ -1652,7 +1653,7 @@ Python-level trace functions in previous versions. | |||
| 1652 | 1653 | The value for the *what* parameter to :c:type:`Py_tracefunc` functions (but not | |
| 1653 | 1654 | profiling functions) when a new opcode is about to be executed. This event is | |
| 1654 | 1655 | not emitted by default: it must be explicitly requested by setting | |
| 1655 | - :attr:`f_trace_opcodes` to *1* on the frame. | ||
| 1656 | + :attr:`~frame.f_trace_opcodes` to *1* on the frame. | ||
| 1656 | 1657 | ||
| 1657 | 1658 | ||
| 1658 | 1659 | .. c:function:: void PyEval_SetProfile(Py_tracefunc func, PyObject *obj) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -673,27 +673,27 @@ iterations of the loop. | |||
| 673 | 673 | ||
| 674 | 674 | Pops a value from the stack, which is used to restore the exception state. | |
| 675 | 675 | ||
| 676 | - .. versionchanged:: 3.11 | ||
| 677 | - Exception representation on the stack now consist of one, not three, items. | ||
| 676 | + .. versionchanged:: 3.11 | ||
| 677 | + Exception representation on the stack now consist of one, not three, items. | ||
| 678 | 678 | ||
| 679 | 679 | .. opcode:: RERAISE | |
| 680 | 680 | ||
| 681 | - Re-raises the exception currently on top of the stack. If oparg is non-zero, | ||
| 682 | - pops an additional value from the stack which is used to set ``f_lasti`` | ||
| 683 | - of the current frame. | ||
| 681 | + Re-raises the exception currently on top of the stack. If oparg is non-zero, | ||
| 682 | + pops an additional value from the stack which is used to set | ||
| 683 | + :attr:`~frame.f_lasti` of the current frame. | ||
| 684 | 684 | ||
| 685 | - .. versionadded:: 3.9 | ||
| 685 | + .. versionadded:: 3.9 | ||
| 686 | 686 | ||
| 687 | - .. versionchanged:: 3.11 | ||
| 688 | - Exception representation on the stack now consist of one, not three, items. | ||
| 687 | + .. versionchanged:: 3.11 | ||
| 688 | + Exception representation on the stack now consist of one, not three, items. | ||
| 689 | 689 | ||
| 690 | 690 | .. opcode:: PUSH_EXC_INFO | |
| 691 | 691 | ||
| 692 | - Pops a value from the stack. Pushes the current exception to the top of the stack. | ||
| 693 | - Pushes the value originally popped back to the stack. | ||
| 694 | - Used in exception handlers. | ||
| 692 | + Pops a value from the stack. Pushes the current exception to the top of the stack. | ||
| 693 | + Pushes the value originally popped back to the stack. | ||
| 694 | + Used in exception handlers. | ||
| 695 | 695 | ||
| 696 | - .. versionadded:: 3.11 | ||
| 696 | + .. versionadded:: 3.11 | ||
| 697 | 697 | ||
| 698 | 698 | .. opcode:: CHECK_EXC_MATCH | |
| 699 | 699 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1541,8 +1541,8 @@ the following flags: | |||
| 1541 | 1541 | ||
| 1542 | 1542 | .. data:: CO_NEWLOCALS | |
| 1543 | 1543 | ||
| 1544 | - If set, a new dict will be created for the frame's ``f_locals`` when | ||
| 1545 | - the code object is executed. | ||
| 1544 | + If set, a new dict will be created for the frame's :attr:`~frame.f_locals` | ||
| 1545 | + when the code object is executed. | ||
| 1546 | 1546 | ||
| 1547 | 1547 | .. data:: CO_VARARGS | |
| 1548 | 1548 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1554,7 +1554,8 @@ always available. | |||
| 1554 | 1554 | :file:`Objects/lnotab_notes.txt` for a detailed explanation of how this | |
| 1555 | 1555 | works. | |
| 1556 | 1556 | Per-line events may be disabled for a frame by setting | |
| 1557 | - :attr:`!f_trace_lines` to :const:`False` on that :ref:`frame <frame-objects>`. | ||
| 1557 | + :attr:`~frame.f_trace_lines` to :const:`False` on that | ||
| 1558 | + :ref:`frame <frame-objects>`. | ||
| 1558 | 1559 | ||
| 1559 | 1560 | ``'return'`` | |
| 1560 | 1561 | A function (or other code block) is about to return. The local trace | |
@@ -1572,7 +1573,7 @@ always available. | |||
| 1572 | 1573 | opcode details). The local trace function is called; *arg* is | |
| 1573 | 1574 | ``None``; the return value specifies the new local trace function. | |
| 1574 | 1575 | Per-opcode events are not emitted by default: they must be explicitly | |
| 1575 | - requested by setting :attr:`!f_trace_opcodes` to :const:`True` on the | ||
| 1576 | + requested by setting :attr:`~frame.f_trace_opcodes` to :const:`True` on the | ||
| 1576 | 1577 | :ref:`frame <frame-objects>`. | |
| 1577 | 1578 | ||
| 1578 | 1579 | Note that as an exception is propagated down the chain of callers, an | |
@@ -1602,8 +1603,8 @@ always available. | |||
| 1602 | 1603 | ||
| 1603 | 1604 | .. versionchanged:: 3.7 | |
| 1604 | 1605 | ||
| 1605 | - ``'opcode'`` event type added; :attr:`!f_trace_lines` and | ||
| 1606 | - :attr:`!f_trace_opcodes` attributes added to frames | ||
| 1606 | + ``'opcode'`` event type added; :attr:`~frame.f_trace_lines` and | ||
| 1607 | + :attr:`~frame.f_trace_opcodes` attributes added to frames | ||
| 1607 | 1608 | ||
| 1608 | 1609 | .. function:: set_asyncgen_hooks(firstiter, finalizer) | |
| 1609 | 1610 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,7 +346,8 @@ Standard names are defined for the following types: | |||
| 346 | 346 | .. data:: GetSetDescriptorType | |
| 347 | 347 | ||
| 348 | 348 | The type of objects defined in extension modules with ``PyGetSetDef``, such | |
| 349 | - as ``FrameType.f_locals`` or ``array.array.typecode``. This type is used as | ||
| 349 | + as :attr:`FrameType.f_locals <frame.f_locals>` or ``array.array.typecode``. | ||
| 350 | + This type is used as | ||
| 350 | 351 | descriptor for object attributes; it has the same purpose as the | |
| 351 | 352 | :class:`property` type, but for classes defined in extension modules. | |
| 352 | 353 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1998,13 +1998,13 @@ Some of the more notable changes are: | |||
| 1998 | 1998 | It would be difficult to detect any resulting difference from Python code, apart | |
| 1999 | 1999 | from a slight speed up when Python is run without :option:`-O`. | |
| 2000 | 2000 | ||
| 2001 | - C extensions that access the :attr:`f_lineno` field of frame objects should | ||
| 2001 | + C extensions that access the :attr:`~frame.f_lineno` field of frame objects should | ||
| 2002 | 2002 | instead call ``PyCode_Addr2Line(f->f_code, f->f_lasti)``. This will have the | |
| 2003 | 2003 | added effect of making the code work as desired under "python -O" in earlier | |
| 2004 | 2004 | versions of Python. | |
| 2005 | 2005 | ||
| 2006 | 2006 | A nifty new feature is that trace functions can now assign to the | |
| 2007 | - :attr:`f_lineno` attribute of frame objects, changing the line that will be | ||
| 2007 | + :attr:`~frame.f_lineno` attribute of frame objects, changing the line that will be | ||
| 2008 | 2008 | executed next. A ``jump`` command has been added to the :mod:`pdb` debugger | |
| 2009 | 2009 | taking advantage of this new feature. (Implemented by Richie Hindle.) | |
| 2010 | 2010 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -399,7 +399,8 @@ PEP 626: Precise line numbers for debugging and other tools | |||
| 399 | 399 | PEP 626 brings more precise and reliable line numbers for debugging, profiling and coverage tools. | |
| 400 | 400 | Tracing events, with the correct line number, are generated for all lines of code executed and only for lines of code that are executed. | |
| 401 | 401 | ||
| 402 | - The ``f_lineno`` attribute of frame objects will always contain the expected line number. | ||
| 402 | + The :attr:`~frame.f_lineno` attribute of frame objects will always contain the | ||
| 403 | + expected line number. | ||
| 403 | 404 | ||
| 404 | 405 | The ``co_lnotab`` attribute of code objects is deprecated and will be removed in 3.12. | |
| 405 | 406 | Code that needs to convert from offset to line number should use the new ``co_lines()`` method instead. | |
@@ -1958,11 +1959,11 @@ Changes in the C API | |||
| 1958 | 1959 | source_buf = PyBytes_AsString(source_bytes_object); | |
| 1959 | 1960 | code = Py_CompileString(source_buf, filename, Py_file_input); | |
| 1960 | 1961 | ||
| 1961 | - * For ``FrameObject`` objects, the ``f_lasti`` member now represents a wordcode | ||
| 1962 | + * For ``FrameObject`` objects, the :attr:`~frame.f_lasti` member now represents a wordcode | ||
| 1962 | 1963 | offset instead of a simple offset into the bytecode string. This means that this | |
| 1963 | 1964 | number needs to be multiplied by 2 to be used with APIs that expect a byte offset | |
| 1964 | 1965 | instead (like :c:func:`PyCode_Addr2Line` for example). Notice as well that the | |
| 1965 | - ``f_lasti`` member of ``FrameObject`` objects is not considered stable: please | ||
| 1966 | + :attr:`!f_lasti` member of ``FrameObject`` objects is not considered stable: please | ||
| 1966 | 1967 | use :c:func:`PyFrame_GetLineNumber` instead. | |
| 1967 | 1968 | ||
| 1968 | 1969 | CPython bytecode changes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2458,11 +2458,12 @@ Porting to Python 3.11 | |||
| 2458 | 2458 | * ``f_valuestack``: removed. | |
| 2459 | 2459 | ||
| 2460 | 2460 | The Python frame object is now created lazily. A side effect is that the | |
| 2461 | - ``f_back`` member must not be accessed directly, since its value is now also | ||
| 2461 | + :attr:`~frame.f_back` member must not be accessed directly, | ||
| 2462 | + since its value is now also | ||
| 2462 | 2463 | computed lazily. The :c:func:`PyFrame_GetBack` function must be called | |
| 2463 | 2464 | instead. | |
| 2464 | 2465 | ||
| 2465 | - Debuggers that accessed the ``f_locals`` directly *must* call | ||
| 2466 | + Debuggers that accessed the :attr:`~frame.f_locals` directly *must* call | ||
| 2466 | 2467 | :c:func:`PyFrame_GetLocals` instead. They no longer need to call | |
| 2467 | 2468 | :c:func:`PyFrame_FastToLocalsWithError` or :c:func:`PyFrame_LocalsToFast`, | |
| 2468 | 2469 | in fact they should not call those functions. The necessary updating of the | |
| Back | FazBrowse Home | New Git URL |
0 commit comments