Skip to content

gh-156725: document O(N) behavior of PyCode_Addr2Line and the private line-table API - #156736

Open
Himesh-rupchandani wants to merge 2 commits into
python:mainfrom
Himesh-rupchandani:gh-156725-code-addrtoline-docs
Open

Himesh-rupchandani wants to merge 2 commits into
python:mainfrom
Himesh-rupchandani:gh-156725-code-addrtoline-docs

Conversation

@Himesh-rupchandani

Copy link
Copy Markdown

Closes gh-156725.

Summary

The C-API docs for PyCode_Addr2Line pointed to the PEP 626 section describing
PyLineTable_InitAddressRange, PyLineTable_NextAddressRange, and
PyLineTable_PreviousAddressRange. Those functions were renamed with a leading
underscore and moved to the private header Include/internal/pycore_code.h; they
are no longer a public C-API.

This docs PR:

  • notes that PyCode_Addr2Line is O(N) in the number of instructions;
  • points to the current private line-table iteration API (_PyCode_InitAddressRange,
    _PyLineTable_NextAddressRange, _PyLineTable_PreviousAddressRange) and flags
    them as internal/unstable.

I left the request to expose these as PyUnstable public APIs as a separate feature
proposal, per the issue.

@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Aug 31, 2026
@python-cla-bot

python-cla-bot Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

read-the-docs-community Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

…rivate line-table API

The C-API docs for PyCode_Addr2Line pointed to the PEP 626 section that
describes PyLineTable_InitAddressRange / PyLineTable_NextAddressRange /
PyLineTable_PreviousAddressRange, but those functions have since been renamed
with a leading underscore and moved to the private header
Include/internal/pycore_code.h.  Point to the current private names, note that
they are not a stable public API, and document that PyCode_Addr2Line is O(N).
@Himesh-rupchandani
Himesh-rupchandani force-pushed the gh-156725-code-addrtoline-docs branch from 3f8d96b to 7707506 Compare August 31, 2026 19:07
Comment thread Doc/c-api/code.rst
Comment on lines +114 to +117
.. warning::
These functions are **internal and not a public C-API**. They are
declared in a private header, may change or be removed without notice,
and are not exported as stable symbols.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should document internal. Users should not be calling them, and pointing it from the docs might send the wrong message.

https://docs.python.org/3/c-api/stable.html#:~:text=Names%20prefixed%20by%20an%20underscore

Comment thread Doc/c-api/code.rst
For efficiently iterating over the line numbers in a code object, use :pep:`the API described in PEP 626
<0626#out-of-process-debuggers-and-profilers>`.
To iterate efficiently over the line numbers in a code object, use the
private, unstable line-table iteration APIs declared in the private header

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

PyCode_Addr2Line point to out of date PEP 626

2 participants