Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea75a51

Browse files
committed
Issue #26010: Document CO_* constants
1 parent 807e2f3 commit ea75a51

1 file changed

Lines changed: 58 additions & 3 deletions

File tree

Doc/library/inspect.rst

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ attributes:
152152
| | co_firstlineno | number of first line in |
153153
| | | Python source code |
154154
+-----------+-----------------+---------------------------+
155-
| | co_flags | bitmap: 1=optimized ``|`` |
156-
| | | 2=newlocals ``|`` 4=\*arg |
157-
| | | ``|`` 8=\*\*arg |
155+
| | co_flags | bitmap of ``CO_*`` flags, |
156+
| | | read more :ref:`here |
157+
| | | <inspect-module-co-flags>`|
158158
+-----------+-----------------+---------------------------+
159159
| | co_lnotab | encoded mapping of line |
160160
| | | numbers to bytecode |
@@ -1232,6 +1232,61 @@ updated as expected:
12321232
.. versionadded:: 3.5
12331233

12341234

1235+
.. _inspect-module-co-flags:
1236+
1237+
Code Objects Bit Flags
1238+
----------------------
1239+
1240+
Python code objects have a ``co_flags`` attribute, which is a bitmap of
1241+
the following flags:
1242+
1243+
.. data:: CO_NEWLOCALS
1244+
1245+
If set, a new dict will be created for the frame's ``f_locals`` when
1246+
the code object is executed.
1247+
1248+
.. data:: CO_VARARGS
1249+
1250+
The code object has a variable positional parameter (``*args``-like).
1251+
1252+
.. data:: CO_VARKEYWORDS
1253+
1254+
The code object has a variable keyword parameter (``**kwargs``-like).
1255+
1256+
.. data:: CO_GENERATOR
1257+
1258+
The flag is set when the code object is a generator function, i.e.
1259+
a generator object is returned when the code object is executed.
1260+
1261+
.. data:: CO_NOFREE
1262+
1263+
The flag is set if there are no free or cell variables.
1264+
1265+
.. data:: CO_COROUTINE
1266+
1267+
The flag is set when the code object is a coroutine function, i.e.
1268+
a coroutine object is returned when the code object is executed. See
1269+
:pep:`492` for more details.
1270+
1271+
.. versionadded:: 3.5
1272+
1273+
.. data:: CO_ITERABLE_COROUTINE
1274+
1275+
Used to turn generators into generator-based coroutines. Generator
1276+
objects with this flag can be used in ``await`` expression, and can
1277+
``yield from`` coroutine objects. See :pep:`492` for more details.
1278+
1279+
.. versionadded:: 3.5
1280+
1281+
.. note::
1282+
The flags are specific to CPython, and may not be defined in other
1283+
Python implementations. Furthermore, the flags are an implementation
1284+
detail, and can be removed or deprecated in future Python releases.
1285+
It's recommended to use public APIs from the :mod:`inspect` module
1286+
for any introspection needs.
1287+
1288+
1289+
12351290
.. _inspect-module-cli:
12361291

12371292
Command Line Interface

0 commit comments

Comments
 (0)