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>
This commit is contained in:
Ammar Askar 2021-07-12 20:29:39 -04:00 committed by GitHub
parent f6954cdfc5
commit 9c3eaf88dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 124 additions and 0 deletions

View file

@ -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