@@ -1202,8 +1202,8 @@ If a code object represents a function, the first item in
12021202:attr: `~codeobject.co_consts ` is
12031203the documentation string of the function, or ``None `` if undefined.
12041204
1205- The :meth: ` !co_positions ` method
1206- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1205+ Methods on code objects
1206+ ~~~~~~~~~~~~~~~~~~~~~~~
12071207
12081208.. method :: codeobject.co_positions()
12091209
@@ -1238,6 +1238,41 @@ The :meth:`!co_positions` method
12381238 :option: `-X ` ``no_debug_ranges `` command line flag or the :envvar: `PYTHONNODEBUGRANGES `
12391239 environment variable can be used.
12401240
1241+ .. method :: codeobject.co_lines()
1242+
1243+ Returns an iterator that yields information about successive ranges of
1244+ :term: `bytecode `\s . Each item yielded is a ``(start, end, lineno) ``
1245+ :class: `tuple `:
1246+
1247+ * ``start `` (an :class: `int `) represents the offset (inclusive) of the start
1248+ of the :term: `bytecode ` range
1249+ * ``end `` (an :class: `int `) represents the offset (inclusive) of the end of
1250+ the :term: `bytecode ` range
1251+ * ``lineno `` is an :class: `int ` representing the line number of the
1252+ :term: `bytecode ` range, or ``None `` if the bytecodes in the given range
1253+ have no line number
1254+
1255+ The items yielded generated will have the following properties:
1256+
1257+ * The first range yielded will have a ``start `` of 0.
1258+ * The ``(start, end) `` ranges will be non-decreasing and consecutive. That
1259+ is, for any pair of :class: `tuple `\s , the ``start `` of the second will be
1260+ equal to the ``end `` of the first.
1261+ * No range will be backwards: ``end >= start `` for all triples.
1262+ * The :class: `tuple ` yielded will have ``end `` equal to the size of the
1263+ :term: `bytecode `.
1264+
1265+ Zero-width ranges, where ``start == end ``, are allowed. Zero-width ranges
1266+ are used for lines that are present in the source code, but have been
1267+ eliminated by the :term: `bytecode ` compiler.
1268+
1269+ .. versionadded :: 3.10
1270+
1271+ .. seealso ::
1272+
1273+ :pep: `626 ` - Precise line numbers for debugging and other tools.
1274+ The PEP that introduced the :meth: `!co_lines ` method.
1275+
12411276
12421277.. _frame-objects :
12431278
0 commit comments