| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,15 +37,15 @@ There are a few functions specific to Python functions. | |||
| 37 | 37 | The function's docstring and name are retrieved from the code object. *__module__* | |
| 38 | 38 | is retrieved from *globals*. The argument defaults, annotations and closure are | |
| 39 | 39 | set to ``NULL``. *__qualname__* is set to the same value as the code object's | |
| 40 | - ``co_qualname`` field. | ||
| 40 | + :attr:`~codeobject.co_qualname` field. | ||
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | 43 | .. c:function:: PyObject* PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname) | |
| 44 | 44 | ||
| 45 | 45 | As :c:func:`PyFunction_New`, but also allows setting the function object's | |
| 46 | 46 | ``__qualname__`` attribute. *qualname* should be a unicode object or ``NULL``; | |
| 47 | 47 | if ``NULL``, the ``__qualname__`` attribute is set to the same value as the | |
| 48 | - code object's ``co_qualname`` field. | ||
| 48 | + code object's :attr:`~codeobject.co_qualname` field. | ||
| 49 | 49 | ||
| 50 | 50 | .. versionadded:: 3.3 | |
| 51 | 51 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -154,7 +154,7 @@ Importing Modules | |||
| 154 | 154 | :class:`~importlib.machinery.SourceFileLoader` otherwise. | |
| 155 | 155 | ||
| 156 | 156 | The module's :attr:`__file__` attribute will be set to the code object's | |
| 157 | - :attr:`!co_filename`. If applicable, :attr:`__cached__` will also | ||
| 157 | + :attr:`~codeobject.co_filename`. If applicable, :attr:`__cached__` will also | ||
| 158 | 158 | be set. | |
| 159 | 159 | ||
| 160 | 160 | This function will reload the module if it was already imported. See | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,8 +346,9 @@ operation is being performed, so the intermediate analysis object isn't useful: | |||
| 346 | 346 | Line numbers can be decreasing. Before, they were always increasing. | |
| 347 | 347 | ||
| 348 | 348 | .. versionchanged:: 3.10 | |
| 349 | - The :pep:`626` ``co_lines`` method is used instead of the ``co_firstlineno`` | ||
| 350 | - and ``co_lnotab`` attributes of the code object. | ||
| 349 | + The :pep:`626` ``co_lines`` method is used instead of the | ||
| 350 | + :attr:`~codeobject.co_firstlineno` and :attr:`~codeobject.co_lnotab` | ||
| 351 | + attributes of the code object. | ||
| 351 | 352 | ||
| 352 | 353 | .. versionchanged:: 3.13 | |
| 353 | 354 | Line numbers can be ``None`` for bytecode that does not map to source lines. | |
@@ -983,13 +984,13 @@ iterations of the loop. | |||
| 983 | 984 | .. opcode:: STORE_NAME (namei) | |
| 984 | 985 | ||
| 985 | 986 | Implements ``name = STACK.pop()``. *namei* is the index of *name* in the attribute | |
| 986 | - :attr:`!co_names` of the :ref:`code object <code-objects>`. | ||
| 987 | + :attr:`~codeobject.co_names` of the :ref:`code object <code-objects>`. | ||
| 987 | 988 | The compiler tries to use :opcode:`STORE_FAST` or :opcode:`STORE_GLOBAL` if possible. | |
| 988 | 989 | ||
| 989 | 990 | ||
| 990 | 991 | .. opcode:: DELETE_NAME (namei) | |
| 991 | 992 | ||
| 992 | - Implements ``del name``, where *namei* is the index into :attr:`!co_names` | ||
| 993 | + Implements ``del name``, where *namei* is the index into :attr:`~codeobject.co_names` | ||
| 993 | 994 | attribute of the :ref:`code object <code-objects>`. | |
| 994 | 995 | ||
| 995 | 996 | ||
@@ -1029,7 +1030,7 @@ iterations of the loop. | |||
| 1029 | 1030 | value = STACK.pop() | |
| 1030 | 1031 | obj.name = value | |
| 1031 | 1032 | ||
| 1032 | - where *namei* is the index of name in :attr:`!co_names` of the | ||
| 1033 | + where *namei* is the index of name in :attr:`~codeobject.co_names` of the | ||
| 1033 | 1034 | :ref:`code object <code-objects>`. | |
| 1034 | 1035 | ||
| 1035 | 1036 | .. opcode:: DELETE_ATTR (namei) | |
@@ -1039,7 +1040,7 @@ iterations of the loop. | |||
| 1039 | 1040 | obj = STACK.pop() | |
| 1040 | 1041 | del obj.name | |
| 1041 | 1042 | ||
| 1042 | - where *namei* is the index of name into :attr:`!co_names` of the | ||
| 1043 | + where *namei* is the index of name into :attr:`~codeobject.co_names` of the | ||
| 1043 | 1044 | :ref:`code object <code-objects>`. | |
| 1044 | 1045 | ||
| 1045 | 1046 | ||
@@ -1402,7 +1403,7 @@ iterations of the loop. | |||
| 1402 | 1403 | Pushes a reference to the object the cell contains on the stack. | |
| 1403 | 1404 | ||
| 1404 | 1405 | .. versionchanged:: 3.11 | |
| 1405 | - ``i`` is no longer offset by the length of ``co_varnames``. | ||
| 1406 | + ``i`` is no longer offset by the length of :attr:`~codeobject.co_varnames`. | ||
| 1406 | 1407 | ||
| 1407 | 1408 | ||
| 1408 | 1409 | .. opcode:: LOAD_FROM_DICT_OR_DEREF (i) | |
@@ -1424,7 +1425,7 @@ iterations of the loop. | |||
| 1424 | 1425 | storage. | |
| 1425 | 1426 | ||
| 1426 | 1427 | .. versionchanged:: 3.11 | |
| 1427 | - ``i`` is no longer offset by the length of ``co_varnames``. | ||
| 1428 | + ``i`` is no longer offset by the length of :attr:`~codeobject.co_varnames`. | ||
| 1428 | 1429 | ||
| 1429 | 1430 | ||
| 1430 | 1431 | .. opcode:: DELETE_DEREF (i) | |
@@ -1435,7 +1436,7 @@ iterations of the loop. | |||
| 1435 | 1436 | .. versionadded:: 3.2 | |
| 1436 | 1437 | ||
| 1437 | 1438 | .. versionchanged:: 3.11 | |
| 1438 | - ``i`` is no longer offset by the length of ``co_varnames``. | ||
| 1439 | + ``i`` is no longer offset by the length of :attr:`~codeobject.co_varnames`. | ||
| 1439 | 1440 | ||
| 1440 | 1441 | ||
| 1441 | 1442 | .. opcode:: COPY_FREE_VARS (n) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1596,8 +1596,8 @@ updated as expected: | |||
| 1596 | 1596 | Code Objects Bit Flags | |
| 1597 | 1597 | ---------------------- | |
| 1598 | 1598 | ||
| 1599 | - Python code objects have a ``co_flags`` attribute, which is a bitmap of | ||
| 1600 | - the following flags: | ||
| 1599 | + Python code objects have a :attr:`~codeobject.co_flags` attribute, | ||
| 1600 | + which is a bitmap of the following flags: | ||
| 1601 | 1601 | ||
| 1602 | 1602 | .. data:: CO_OPTIMIZED | |
| 1603 | 1603 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1077,57 +1077,111 @@ indirectly) to mutable objects. | |||
| 1077 | 1077 | single: co_freevars (code object attribute) | |
| 1078 | 1078 | single: co_qualname (code object attribute) | |
| 1079 | 1079 | ||
| 1080 | - Special read-only attributes: :attr:`co_name` gives the function name; | ||
| 1081 | - :attr:`co_qualname` gives the fully qualified function name; | ||
| 1082 | - :attr:`co_argcount` is the total number of positional arguments | ||
| 1083 | - (including positional-only arguments and arguments with default values); | ||
| 1084 | - :attr:`co_posonlyargcount` is the number of positional-only arguments | ||
| 1085 | - (including arguments with default values); :attr:`co_kwonlyargcount` is | ||
| 1086 | - the number of keyword-only arguments (including arguments with default | ||
| 1087 | - values); :attr:`co_nlocals` is the number of local variables used by the | ||
| 1088 | - function (including arguments); :attr:`co_varnames` is a tuple containing | ||
| 1089 | - the names of the local variables (starting with the argument names); | ||
| 1090 | - :attr:`co_cellvars` is a tuple containing the names of local variables | ||
| 1091 | - that are referenced by nested functions; :attr:`co_freevars` is a tuple | ||
| 1092 | - containing the names of free variables; :attr:`co_code` is a string | ||
| 1093 | - representing the sequence of bytecode instructions; :attr:`co_consts` is | ||
| 1094 | - a tuple containing the literals used by the bytecode; :attr:`co_names` is | ||
| 1095 | - a tuple containing the names used by the bytecode; :attr:`co_filename` is | ||
| 1096 | - the filename from which the code was compiled; :attr:`co_firstlineno` is | ||
| 1097 | - the first line number of the function; :attr:`co_lnotab` is a string | ||
| 1098 | - encoding the mapping from bytecode offsets to line numbers (for details | ||
| 1099 | - see the source code of the interpreter, is deprecated since 3.12 | ||
| 1100 | - and may be removed in 3.14); :attr:`co_stacksize` is the | ||
| 1101 | - required stack size; :attr:`co_flags` is an integer encoding a number | ||
| 1102 | - of flags for the interpreter. | ||
| 1080 | + Special read-only attributes | ||
| 1081 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 1082 | + | ||
| 1083 | + .. list-table:: | ||
| 1084 | + | ||
| 1085 | + * - .. attribute:: codeobject.co_name | ||
| 1086 | + - The function name | ||
| 1087 | + | ||
| 1088 | + * - .. attribute:: codeobject.co_qualname | ||
| 1089 | + - The fully qualified function name | ||
| 1090 | + | ||
| 1091 | + * - .. attribute:: codeobject.co_argcount | ||
| 1092 | + - The total number of positional :term:`parameters <parameter>` | ||
| 1093 | + (including positional-only parameters and parameters with default values) | ||
| 1094 | + that the function has | ||
| 1095 | + | ||
| 1096 | + * - .. attribute:: codeobject.co_posonlyargcount | ||
| 1097 | + - The number of positional-only :term:`parameters <parameter>` | ||
| 1098 | + (including arguments with default values) that the function has | ||
| 1099 | + | ||
| 1100 | + * - .. attribute:: codeobject.co_kwonlyargcount | ||
| 1101 | + - The number of keyword-only :term:`parameters <parameter>` | ||
| 1102 | + (including arguments with default values) that the function has | ||
| 1103 | + | ||
| 1104 | + * - .. attribute:: codeobject.co_nlocals | ||
| 1105 | + - The number of :ref:`local variables <naming>` used by the function | ||
| 1106 | + (including parameters) | ||
| 1107 | + | ||
| 1108 | + * - .. attribute:: codeobject.co_varnames | ||
| 1109 | + - A :class:`tuple` containing the names of the local variables in the | ||
| 1110 | + function (starting with the parameter names) | ||
| 1111 | + | ||
| 1112 | + * - .. attribute:: codeobject.co_cellvars | ||
| 1113 | + - A :class:`tuple` containing the names of :ref:`local variables <naming>` | ||
| 1114 | + that are referenced by nested functions inside the function | ||
| 1115 | + | ||
| 1116 | + * - .. attribute:: codeobject.co_freevars | ||
| 1117 | + - A :class:`tuple` containing the names of free variables in the function | ||
| 1118 | + | ||
| 1119 | + * - .. attribute:: codeobject.co_code | ||
| 1120 | + - A string representing the sequence of :term:`bytecode` instructions in | ||
| 1121 | + the function | ||
| 1122 | + | ||
| 1123 | + * - .. attribute:: codeobject.co_consts | ||
| 1124 | + - A :class:`tuple` containing the literals used by the :term:`bytecode` in | ||
| 1125 | + the function | ||
| 1126 | + | ||
| 1127 | + * - .. attribute:: codeobject.co_names | ||
| 1128 | + - A :class:`tuple` containing the names used by the :term:`bytecode` in | ||
| 1129 | + the function | ||
| 1130 | + | ||
| 1131 | + * - .. attribute:: codeobject.co_filename | ||
| 1132 | + - The name of the file from which the code was compiled | ||
| 1133 | + | ||
| 1134 | + * - .. attribute:: codeobject.co_firstlineno | ||
| 1135 | + - The line number of the first line of the function | ||
| 1136 | + | ||
| 1137 | + * - .. attribute:: codeobject.co_lnotab | ||
| 1138 | + - A string encoding the mapping from :term:`bytecode` offsets to line | ||
| 1139 | + numbers. For details, see the source code of the interpreter. | ||
| 1140 | + | ||
| 1141 | + .. deprecated:: 3.12 | ||
| 1142 | + This attribute of code objects is deprecated, and may be removed in | ||
| 1143 | + Python 3.14. | ||
| 1144 | + | ||
| 1145 | + * - .. attribute:: codeobject.co_stacksize | ||
| 1146 | + - The required stack size of the code object | ||
| 1147 | + | ||
| 1148 | + * - .. attribute:: codeobject.co_flags | ||
| 1149 | + - An :class:`integer <int>` encoding a number of flags for the | ||
| 1150 | + interpreter. | ||
| 1103 | 1151 | ||
| 1104 | 1152 | .. index:: pair: object; generator | |
| 1105 | 1153 | ||
| 1106 | - The following flag bits are defined for :attr:`co_flags`: bit ``0x04`` is set if | ||
| 1154 | + The following flag bits are defined for :attr:`~codeobject.co_flags`: | ||
| 1155 | + bit ``0x04`` is set if | ||
| 1107 | 1156 | the function uses the ``*arguments`` syntax to accept an arbitrary number of | |
| 1108 | 1157 | positional arguments; bit ``0x08`` is set if the function uses the | |
| 1109 | 1158 | ``**keywords`` syntax to accept arbitrary keyword arguments; bit ``0x20`` is set | |
| 1110 | - if the function is a generator. | ||
| 1159 | + if the function is a generator. See :ref:`inspect-module-co-flags` for details | ||
| 1160 | + on the semantics of each flags that might be present. | ||
| 1111 | 1161 | ||
| 1112 | 1162 | Future feature declarations (``from __future__ import division``) also use bits | |
| 1113 | - in :attr:`co_flags` to indicate whether a code object was compiled with a | ||
| 1163 | + in :attr:`~codeobject.co_flags` to indicate whether a code object was compiled with a | ||
| 1114 | 1164 | particular feature enabled: bit ``0x2000`` is set if the function was compiled | |
| 1115 | 1165 | with future division enabled; bits ``0x10`` and ``0x1000`` were used in earlier | |
| 1116 | 1166 | versions of Python. | |
| 1117 | 1167 | ||
| 1118 | - Other bits in :attr:`co_flags` are reserved for internal use. | ||
| 1168 | + Other bits in :attr:`~codeobject.co_flags` are reserved for internal use. | ||
| 1119 | 1169 | ||
| 1120 | 1170 | .. index:: single: documentation string | |
| 1121 | 1171 | ||
| 1122 | - If a code object represents a function, the first item in :attr:`co_consts` is | ||
| 1172 | + If a code object represents a function, the first item in | ||
| 1173 | + :attr:`~codeobject.co_consts` is | ||
| 1123 | 1174 | the documentation string of the function, or ``None`` if undefined. | |
| 1124 | 1175 | ||
| 1176 | + The :meth:`!co_positions` method | ||
| 1177 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 1178 | + | ||
| 1125 | 1179 | .. method:: codeobject.co_positions() | |
| 1126 | 1180 | ||
| 1127 | - Returns an iterable over the source code positions of each bytecode | ||
| 1181 | + Returns an iterable over the source code positions of each :term:`bytecode` | ||
| 1128 | 1182 | instruction in the code object. | |
| 1129 | 1183 | ||
| 1130 | - The iterator returns tuples containing the ``(start_line, end_line, | ||
| 1184 | + The iterator returns :class:`tuple`\s containing the ``(start_line, end_line, | ||
| 1131 | 1185 | start_column, end_column)``. The *i-th* tuple corresponds to the | |
| 1132 | 1186 | position of the source code that compiled to the *i-th* instruction. | |
| 1133 | 1187 | Column information is 0-indexed utf-8 byte offsets on the given source | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2405,7 +2405,7 @@ Other Changes and Fixes | |||
| 2405 | 2405 | :issue:`5464`.) | |
| 2406 | 2406 | ||
| 2407 | 2407 | * When importing a module from a :file:`.pyc` or :file:`.pyo` file | |
| 2408 | - with an existing :file:`.py` counterpart, the :attr:`co_filename` | ||
| 2408 | + with an existing :file:`.py` counterpart, the :attr:`~codeobject.co_filename` | ||
| 2409 | 2409 | attributes of the resulting code objects are overwritten when the | |
| 2410 | 2410 | original filename is obsolete. This can happen if the file has been | |
| 2411 | 2411 | renamed, moved, or is accessed through different paths. (Patch by | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -402,7 +402,8 @@ Tracing events, with the correct line number, are generated for all lines of cod | |||
| 402 | 402 | The :attr:`~frame.f_lineno` attribute of frame objects will always contain the | |
| 403 | 403 | expected line number. | |
| 404 | 404 | ||
| 405 | - The ``co_lnotab`` attribute of code objects is deprecated and will be removed in 3.12. | ||
| 405 | + The :attr:`~codeobject.co_lnotab` attribute of code objects is deprecated and | ||
| 406 | + will be removed in 3.12. | ||
| 406 | 407 | Code that needs to convert from offset to line number should use the new ``co_lines()`` method instead. | |
| 407 | 408 | ||
| 408 | 409 | PEP 634: Structural Pattern Matching | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1323,7 +1323,8 @@ Deprecated | |||
| 1323 | 1323 | ``int``, convert to int explicitly: ``~int(x)``. (Contributed by Tim Hoffmann | |
| 1324 | 1324 | in :gh:`103487`.) | |
| 1325 | 1325 | ||
| 1326 | - * Accessing ``co_lnotab`` on code objects was deprecated in Python 3.10 via :pep:`626`, | ||
| 1326 | + * Accessing :attr:`~codeobject.co_lnotab` on code objects was deprecated in | ||
| 1327 | + Python 3.10 via :pep:`626`, | ||
| 1327 | 1328 | but it only got a proper :exc:`DeprecationWarning` in 3.12, | |
| 1328 | 1329 | therefore it will be removed in 3.14. | |
| 1329 | 1330 | (Contributed by Nikita Sobolev in :gh:`101866`.) | |
@@ -1430,7 +1431,7 @@ and will be removed in Python 3.14. | |||
| 1430 | 1431 | ||
| 1431 | 1432 | * The ``__package__`` and ``__cached__`` attributes on module objects. | |
| 1432 | 1433 | ||
| 1433 | - * The ``co_lnotab`` attribute of code objects. | ||
| 1434 | + * The :attr:`~codeobject.co_lnotab` attribute of code objects. | ||
| 1434 | 1435 | ||
| 1435 | 1436 | Pending Removal in Python 3.15 | |
| 1436 | 1437 | ------------------------------ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -572,7 +572,8 @@ Pending Removal in Python 3.14 | |||
| 572 | 572 | * date and datetime adapter, date and timestamp converter: | |
| 573 | 573 | see the :mod:`sqlite3` documentation for suggested replacement recipes. | |
| 574 | 574 | ||
| 575 | - * :class:`types.CodeType`: Accessing ``co_lnotab`` was deprecated in :pep:`626` | ||
| 575 | + * :class:`types.CodeType`: Accessing :attr:`~codeobject.co_lnotab` was | ||
| 576 | + deprecated in :pep:`626` | ||
| 576 | 577 | since 3.10 and was planned to be removed in 3.12, | |
| 577 | 578 | but it only got a proper :exc:`DeprecationWarning` in 3.12. | |
| 578 | 579 | May be removed in 3.14. | |
@@ -735,7 +736,7 @@ although there is currently no date scheduled for their removal. | |||
| 735 | 736 | ||
| 736 | 737 | * :mod:`!sre_compile`, :mod:`!sre_constants` and :mod:`!sre_parse` modules. | |
| 737 | 738 | ||
| 738 | - * ``types.CodeType.co_lnotab``: use the ``co_lines`` attribute instead. | ||
| 739 | + * :attr:`~codeobject.co_lnotab`: use the ``co_lines`` attribute instead. | ||
| 739 | 740 | ||
| 740 | 741 | * :class:`typing.Text` (:gh:`92332`). | |
| 741 | 742 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2160,14 +2160,15 @@ Changes in the Python API | |||
| 2160 | 2160 | * :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg** | |
| 2161 | 2161 | argument is not set. Previously only ``NULL`` was returned. | |
| 2162 | 2162 | ||
| 2163 | - * The format of the ``co_lnotab`` attribute of code objects changed to support | ||
| 2163 | + * The format of the :attr:`~codeobject.co_lnotab` attribute of code objects | ||
| 2164 | + changed to support | ||
| 2164 | 2165 | a negative line number delta. By default, Python does not emit bytecode with | |
| 2165 | 2166 | a negative line number delta. Functions using :attr:`frame.f_lineno`, | |
| 2166 | 2167 | ``PyFrame_GetLineNumber()`` or ``PyCode_Addr2Line()`` are not affected. | |
| 2167 | - Functions directly decoding ``co_lnotab`` should be updated to use a signed | ||
| 2168 | + Functions directly decoding :attr:`!co_lnotab` should be updated to use a signed | ||
| 2168 | 2169 | 8-bit integer type for the line number delta, but this is only required to | |
| 2169 | 2170 | support applications using a negative line number delta. See | |
| 2170 | - ``Objects/lnotab_notes.txt`` for the ``co_lnotab`` format and how to decode | ||
| 2171 | + ``Objects/lnotab_notes.txt`` for the :attr:`!co_lnotab` format and how to decode | ||
| 2171 | 2172 | it, and see the :pep:`511` for the rationale. | |
| 2172 | 2173 | ||
| 2173 | 2174 | * The functions in the :mod:`compileall` module now return booleans instead | |
| Back | FazBrowse Home | New Git URL |
0 commit comments