@@ -1064,56 +1064,107 @@ indirectly) to mutable objects.
1064
1064
single: co_freevars (code object attribute)
1065
1065
single: co_qualname (code object attribute)
1066
1066
1067
- Special read-only attributes: :attr: `co_name ` gives the function name;
1068
- :attr: `co_qualname ` gives the fully qualified function name;
1069
- :attr: `co_argcount ` is the total number of positional arguments
1070
- (including positional-only arguments and arguments with default values);
1071
- :attr: `co_posonlyargcount ` is the number of positional-only arguments
1072
- (including arguments with default values); :attr: `co_kwonlyargcount ` is
1073
- the number of keyword-only arguments (including arguments with default
1074
- values); :attr: `co_nlocals ` is the number of local variables used by the
1075
- function (including arguments); :attr: `co_varnames ` is a tuple containing
1076
- the names of the local variables (starting with the argument names);
1077
- :attr: `co_cellvars ` is a tuple containing the names of local variables
1078
- that are referenced by nested functions; :attr: `co_freevars ` is a tuple
1079
- containing the names of free variables; :attr: `co_code ` is a string
1080
- representing the sequence of bytecode instructions; :attr: `co_consts ` is
1081
- a tuple containing the literals used by the bytecode; :attr: `co_names ` is
1082
- a tuple containing the names used by the bytecode; :attr: `co_filename ` is
1083
- the filename from which the code was compiled; :attr: `co_firstlineno ` is
1084
- the first line number of the function; :attr: `co_lnotab ` is a string
1085
- encoding the mapping from bytecode offsets to line numbers (for details
1086
- see the source code of the interpreter); :attr: `co_stacksize ` is the
1087
- required stack size; :attr: `co_flags ` is an integer encoding a number
1088
- of flags for the interpreter.
1067
+ Special read-only attributes
1068
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1069
+
1070
+ .. list-table ::
1071
+
1072
+ * - .. attribute:: codeobject.co_name
1073
+ - The function name
1074
+
1075
+ * - .. attribute:: codeobject.co_qualname
1076
+ - The fully qualified function name
1077
+
1078
+ * - .. attribute:: codeobject.co_argcount
1079
+ - The total number of positional :term: `parameters <parameter> `
1080
+ (including positional-only parameters and parameters with default values)
1081
+ that the function has
1082
+
1083
+ * - .. attribute:: codeobject.co_posonlyargcount
1084
+ - The number of positional-only :term: `parameters <parameter> `
1085
+ (including arguments with default values) that the function has
1086
+
1087
+ * - .. attribute:: codeobject.co_kwonlyargcount
1088
+ - The number of keyword-only :term: `parameters <parameter> `
1089
+ (including arguments with default values) that the function has
1090
+
1091
+ * - .. attribute:: codeobject.co_nlocals
1092
+ - The number of :ref: `local variables <naming >` used by the function
1093
+ (including parameters)
1094
+
1095
+ * - .. attribute:: codeobject.co_varnames
1096
+ - A :class: `tuple ` containing the names of the local variables in the
1097
+ function (starting with the parameter names)
1098
+
1099
+ * - .. attribute:: codeobject.co_cellvars
1100
+ - A :class: `tuple ` containing the names of :ref: `local variables <naming >`
1101
+ that are referenced by nested functions inside the function
1102
+
1103
+ * - .. attribute:: codeobject.co_freevars
1104
+ - A :class: `tuple ` containing the names of free variables in the function
1105
+
1106
+ * - .. attribute:: codeobject.co_code
1107
+ - A string representing the sequence of :term: `bytecode ` instructions in
1108
+ the function
1109
+
1110
+ * - .. attribute:: codeobject.co_consts
1111
+ - A :class: `tuple ` containing the literals used by the :term: `bytecode ` in
1112
+ the function
1113
+
1114
+ * - .. attribute:: codeobject.co_names
1115
+ - A :class: `tuple ` containing the names used by the :term: `bytecode ` in
1116
+ the function
1117
+
1118
+ * - .. attribute:: codeobject.co_filename
1119
+ - The name of the file from which the code was compiled
1120
+
1121
+ * - .. attribute:: codeobject.co_firstlineno
1122
+ - The line number of the first line of the function
1123
+
1124
+ * - .. attribute:: codeobject.co_lnotab
1125
+ - A string encoding the mapping from :term: `bytecode ` offsets to line
1126
+ numbers. For details, see the source code of the interpreter.
1127
+
1128
+ * - .. attribute:: codeobject.co_stacksize
1129
+ - The required stack size of the code object
1130
+
1131
+ * - .. attribute:: codeobject.co_flags
1132
+ - An :class: `integer <int> ` encoding a number of flags for the
1133
+ interpreter.
1089
1134
1090
1135
.. index :: pair: object; generator
1091
1136
1092
- The following flag bits are defined for :attr: `co_flags `: bit ``0x04 `` is set if
1137
+ The following flag bits are defined for :attr: `~codeobject.co_flags `:
1138
+ bit ``0x04 `` is set if
1093
1139
the function uses the ``*arguments `` syntax to accept an arbitrary number of
1094
1140
positional arguments; bit ``0x08 `` is set if the function uses the
1095
1141
``**keywords `` syntax to accept arbitrary keyword arguments; bit ``0x20 `` is set
1096
- if the function is a generator.
1142
+ if the function is a generator. See :ref: `inspect-module-co-flags ` for details
1143
+ on the semantics of each flags that might be present.
1097
1144
1098
1145
Future feature declarations (``from __future__ import division ``) also use bits
1099
- in :attr: `co_flags ` to indicate whether a code object was compiled with a
1146
+ in :attr: `~codeobject. co_flags ` to indicate whether a code object was compiled with a
1100
1147
particular feature enabled: bit ``0x2000 `` is set if the function was compiled
1101
1148
with future division enabled; bits ``0x10 `` and ``0x1000 `` were used in earlier
1102
1149
versions of Python.
1103
1150
1104
- Other bits in :attr: `co_flags ` are reserved for internal use.
1151
+ Other bits in :attr: `~codeobject. co_flags ` are reserved for internal use.
1105
1152
1106
1153
.. index :: single: documentation string
1107
1154
1108
- If a code object represents a function, the first item in :attr: `co_consts ` is
1155
+ If a code object represents a function, the first item in
1156
+ :attr: `~codeobject.co_consts ` is
1109
1157
the documentation string of the function, or ``None `` if undefined.
1110
1158
1159
+ The :meth: `!co_positions ` method
1160
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1161
+
1111
1162
.. method :: codeobject.co_positions()
1112
1163
1113
- Returns an iterable over the source code positions of each bytecode
1164
+ Returns an iterable over the source code positions of each :term: ` bytecode `
1114
1165
instruction in the code object.
1115
1166
1116
- The iterator returns tuples containing the ``(start_line, end_line,
1167
+ The iterator returns :class: ` tuple ` \s containing the ``(start_line, end_line,
1117
1168
start_column, end_column) ``. The *i-th * tuple corresponds to the
1118
1169
position of the source code that compiled to the *i-th * instruction.
1119
1170
Column information is 0-indexed utf-8 byte offsets on the given source
0 commit comments