GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@xionghul xionghul commented Nov 11, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

  • Issue: inspect.getframeinfo and traceback build every preceding co_positions() tuple #161799

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@xionghul @cursoragent
Look up one bytecode position in inspect and traceback
8af6c9a
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]>
@xionghul
xionghul requested a review from markshannon as a code owner November 11, 2026 09:13
@python-cla-bot

python-cla-bot Bot commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Nov 11, 2026
inspect.getframeinfo and traceback build every preceding co_positions() tuple #161799
Open
@bedevere-app bedevere-app Bot added the awaiting review label Nov 11, 2026
@xionghul @cursoragent
Use the issue number in the inspect position NEWS entry
f45a24d
blurb rejects gh-issue-0, which failed the documentation build.

Co-authored-by: Cursor <[email protected]>
@picnixz

picnixz commented Nov 11, 2026

Copy link
Copy Markdown
Member

I am not convinced by this change. Until it has been more discussed on the issue, I'm closing the PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz closed this Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

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

Labels

awaiting review

Projects

None yet

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.

2 participants

@xionghul @picnixz
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.