GeezerVison is showing github.com — gh-161799: Look up one bytecode position in inspect and traceback by xionghul · Pull Request #161800 · python/cpython
Conversation
xionghul
commented
Nov 11, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
inspect.getframeinfo() and traceback read the current instruction with itertools.islice(code.co_positions(), lasti // 2). co_positions() yields one tuple per instruction, so islice builds and discards a tuple for every preceding instruction. Callers such as inspect.stack(0) do this for every frame, and the cost grows with the size of the code object.
The byte offset is the same value traceback.c already passes to PyCode_Addr2Location. Expose that lookup as the private method code._co_position_at() and use it for real code objects. The returned tuple matches co_positions(), including None where a column is missing. Objects that only implement co_positions() keep the iterator path. Filename selection is unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
inspect.getframeinfo() and traceback read the current instruction with
itertools.islice(code.co_positions(), lasti // 2). co_positions() yields
one tuple per instruction, so islice builds and discards a tuple for
every preceding instruction. Callers such as inspect.stack(0) do this
for every frame, and the cost grows with the size of the code object.
The byte offset is the same value traceback.c already passes to
PyCode_Addr2Location. Expose that lookup as the private method
code._co_position_at() and use it for real code objects. The returned
tuple matches co_positions(), including None where a column is missing.
Objects that only implement co_positions() keep the iterator path.
Filename selection is unchanged.
Co-authored-by: Cursor <[email protected]>
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
blurb rejects gh-issue-0, which failed the documentation build.
Co-authored-by: Cursor <[email protected]>
|
I am not convinced by this change. Until it has been more discussed on the issue, I'm closing the PR.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
markshannon
Awaiting requested review from markshannon
markshannon is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.