@@ -1077,57 +1077,111 @@ indirectly) to mutable objects.
10771077 single: co_freevars (code object attribute)
10781078 single: co_qualname (code object attribute)
10791079
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.
11031151
11041152.. index :: pair: object; generator
11051153
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
11071156the function uses the ``*arguments `` syntax to accept an arbitrary number of
11081157positional arguments; bit ``0x08 `` is set if the function uses the
11091158``**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.
11111161
11121162Future 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
11141164particular feature enabled: bit ``0x2000 `` is set if the function was compiled
11151165with future division enabled; bits ``0x10 `` and ``0x1000 `` were used in earlier
11161166versions of Python.
11171167
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.
11191169
11201170.. index :: single: documentation string
11211171
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
11231174the documentation string of the function, or ``None `` if undefined.
11241175
1176+ The :meth: `!co_positions ` method
1177+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1178+
11251179.. method :: codeobject.co_positions()
11261180
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 `
11281182 instruction in the code object.
11291183
1130- The iterator returns tuples containing the ``(start_line, end_line,
1184+ The iterator returns :class: ` tuple ` \s containing the ``(start_line, end_line,
11311185 start_column, end_column) ``. The *i-th * tuple corresponds to the
11321186 position of the source code that compiled to the *i-th * instruction.
11331187 Column information is 0-indexed utf-8 byte offsets on the given source
0 commit comments