summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorAmmar Askar <ammar@ammaraskar.com>2021-07-13 00:29:39 (GMT)
committerGitHub <noreply@github.com>2021-07-13 00:29:39 (GMT)
commit9c3eaf88dc5d5bed80cc45936de06b7b3162bc6d (patch)
tree939b88e14214adcc49e19f4a3d9c12b3192046d3 /Doc/reference
parentf6954cdfc50060a54318fb2aea4d80408381243a (diff)
downloadcpython-9c3eaf88dc5d5bed80cc45936de06b7b3162bc6d.zip
cpython-9c3eaf88dc5d5bed80cc45936de06b7b3162bc6d.tar.gz
cpython-9c3eaf88dc5d5bed80cc45936de06b7b3162bc6d.tar.bz2
bpo-43950: Add documentation for PEP-657 (GH-27047)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/datamodel.rst33
1 files changed, 33 insertions, 0 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index b6dae81..bb0b7e0 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1015,6 +1015,39 @@ Internal types
If a code object represents a function, the first item in :attr:`co_consts` is
the documentation string of the function, or ``None`` if undefined.
+ .. method:: codeobject.co_positions()
+
+ Returns an iterable over the source code positions of each bytecode
+ instruction in the code object.
+
+ The iterator returns tuples containing the ``(start_line, end_line,
+ start_column, end_column)``. The *i-th* tuple corresponds to the
+ position of the source code that compiled to the *i-th* instruction.
+ Column information is 0-indexed utf-8 byte offsets on the given source
+ line.
+
+ This positional information can be missing. A non-exhaustive lists of
+ cases where this may happen:
+
+ - Running the interpreter with :option:`-X` ``no_debug_ranges``.
+ - Loading a pyc file compiled while using :option:`-X` ``no_debug_ranges``.
+ - Position tuples corresponding to artificial instructions.
+ - Line and column numbers that can't be represented due to
+ implementation specific limitations.
+
+ When this occurs, some or all of the tuple elements can be
+ :const:`None`.
+
+ .. versionadded:: 3.11
+
+ .. note::
+ This feature requires storing column positions in code objects which may
+ result in a small increase of disk usage of compiled Python files or
+ interpreter memory usage. To avoid storing the extra information and/or
+ deactivate printing the extra traceback information, the
+ :option:`-X` ``no_debug_ranges`` command line flag or the :envvar:`PYTHONNODEBUGRANGES`
+ environment variable can be used.
+
.. _frame-objects:
Frame objects