Skip to content

Commit 2991089

Browse files
authored
PEP 657: Update the env variable name and the C-API and add some clarifications (#2015)
1 parent a8e7358 commit 2991089

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

pep-0657.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,16 @@ this PEP:
191191
four-element tuples containing the full location of every instruction
192192
(including start line, end line, start column offset and end column offset)
193193
or ``None`` if the code object was created without the offset information.
194-
* Three new C-API functions, ``PyCode_Addr2EndLine``, ``PyCode_Addr2StartOffset``
195-
and ``PyCode_Addr2EndOffset`` will be added that can obtain the end line, the
196-
start column offsets and the end column offset respectively given the index
197-
of a bytecode instruction. These functions will return 0 if the information
198-
is not available.
194+
* One new C-API function: ::
195+
196+
int PyCode_Addr2Location(
197+
PyCodeObject *co, int addr,
198+
int *startline, int *startcolumn,
199+
int *endline, int *endcolumn)
200+
201+
will be added so the end line, the start column offsets and the end column
202+
offset can be obtained given the index of a bytecode instruction. This
203+
function will set the values to 0 if the information is not available.
199204

200205
The internal storage, compression and encoding of the information is left as an
201206
implementation detail and can be changed at any point as long as the public API
@@ -311,18 +316,22 @@ storage and memory overhead and to allow third party tools and other
311316
programs that are currently parsing tracebacks to catch up the following
312317
methods will be provided to deactivate this feature:
313318

314-
* A new environment variable: ``PYNODEBUGRANGES``.
319+
* A new environment variable: ``PYTHONNODEBUGRANGES``.
315320
* A new command line option for the dev mode: ``python -Xnodebugranges``.
316321

317322
If any of these methods are used, the Python compiler will **not** populate
318323
code objects with the new information (``None`` will be used instead) and any
319324
unmarshalled code objects that contain the extra information will have it stripped
320-
away and replaced with ``None``). This method allows users to:
325+
away and replaced with ``None``). Additionally, the traceback machinery will not
326+
show the extended location information even if the information was present.
327+
This method allows users to:
321328

322329
* Create smaller ``pyc`` files by using one of the two methods when said files
323330
are created.
324331
* Don't load the extra information from ``pyc`` files if those were created with
325332
the extra information in the first place.
333+
* Deactivate the extra information when displaying tracebacks (the caret characters
334+
indicating the location of the error).
326335

327336
Doing this has a **very small** performance hit as the interpreter state needs
328337
to be fetched when code objects are created to look up the configuration.

0 commit comments

Comments
 (0)