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-141518: Add PyUnstable_InterpreterState_SetEvalFrameFunc() by vstinner · Pull Request #141665 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Nov 17, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Add a PyUnstable API for PEP 523:

  • PyUnstable_FrameEvalFunction type
  • PyUnstable_InterpreterState_GetEvalFrameFunc()
  • PyUnstable_InterpreterState_SetEvalFrameFunc()

Keep the old names as deprecated aliases to new names:

  • _PyFrameEvalFunction
  • _PyInterpreterState_GetEvalFrameFunc
  • _PyInterpreterState_SetEvalFrameFunc
  • Issue: [C API] Promote PEP 523 functions to public functions: add PyUnstable_InterpreterState_SetEvalFrameFunc() #141518

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
pythongh-141518: Add PyUnstable_InterpreterState_SetEvalFrameFunc()
0e322e4
Add PyUnstable API for PEP 523:

* PyUnstable_FrameEvalFunction type
* PyUnstable_InterpreterState_GetEvalFrameFunc()
* PyUnstable_InterpreterState_SetEvalFrameFunc()

Keep the old names as deprecated aliases to new names:

* _PyFrameEvalFunction
* _PyInterpreterState_GetEvalFrameFunc
* _PyInterpreterState_SetEvalFrameFunc
@vstinner
vstinner requested a review from ericsnowcurrently as a code owner November 17, 2025 15:09
@vstinner vstinner added the topic-C-API label Nov 17, 2025
@vstinner
vstinner requested review from AA-Turner and ZeroIntensity as code owners November 17, 2025 15:09
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 17, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 17, 2025
[C API] Promote PEP 523 functions to public functions: add PyUnstable_InterpreterState_SetEvalFrameFunc() #141518
Closed
@vstinner
Deprecate the old C API
757eada
efimov-mikhail
efimov-mikhail reviewed Nov 17, 2025
View reviewed changes
Comment thread Doc/c-api/init.rst Resolved

Uh oh!

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

Comment thread Doc/deprecations/c-api-pending-removal-in-3.20.rst Resolved

Uh oh!

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

Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

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

@efimov-mikhail

efimov-mikhail commented Nov 17, 2025

Copy link
Copy Markdown
Member

Do we need tests on PyUnstable API?

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Nov 17, 2025

Copy link
Copy Markdown
Member Author

Do we need tests on PyUnstable API?

There are tests in test_optimizer: see _testinternalcapi.set_eval_frame_default().

All reactions

Sorry, something went wrong.

Uh oh!

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

@efimov-mikhail

efimov-mikhail commented Nov 17, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Do we need tests on PyUnstable API?

There are tests in test_optimizer: see _testinternalcapi.set_eval_frame_default().

Thanks!
But it's only on PyUnstable_InterpreterState_SetEvalFrameFunc.
Maybe we want to test PyUnstable_InterpreterState_GetEvalFrameFunc a little?

All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner added 2 commits November 17, 2025 23:22
@vstinner
Fix PyUnstable_FrameEvalFunction doc
4ceff72
@vstinner
Add tests
0a8d7cd
@vstinner

vstinner commented Nov 17, 2025

Copy link
Copy Markdown
Member Author

Maybe we want to test PyUnstable_InterpreterState_GetEvalFrameFunc a little?

I added tests.

All reactions

Sorry, something went wrong.

Uh oh!

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

efimov-mikhail
efimov-mikhail reviewed Nov 18, 2025
View reviewed changes
Comment thread Modules/_testcapimodule.c Resolved

Uh oh!

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

Comment thread Modules/_testcapimodule.c Resolved

Uh oh!

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

@vstinner @efimov-mikhail
Update Modules/_testcapimodule.c
f694542
Co-authored-by: Mikhail Efimov <[email protected]>
efimov-mikhail
efimov-mikhail approved these changes Nov 18, 2025
View reviewed changes
@vstinner

vstinner commented Nov 18, 2025

Copy link
Copy Markdown
Member Author

cc @emmatyping

All reactions

Sorry, something went wrong.

Uh oh!

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

emmatyping
emmatyping approved these changes Nov 18, 2025
View reviewed changes

@emmatyping emmatyping left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

One question but otherwise looks good!

Sorry, something went wrong.

Uh oh!

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

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

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

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Nov 18, 2025
vstinner added 2 commits November 19, 2025 11:35
@vstinner
Fix copy/paste mistake
3e48d91
@vstinner
Merge branch 'main' into eval_frame_func
c167f44
@vstinner vstinner mentioned this pull request Nov 19, 2025
Add PyUnstable_InterpreterState_SetEvalFrameFunc() function capi-workgroup/decisions#89
Closed
@vstinner

vstinner commented Nov 19, 2025

Copy link
Copy Markdown
Member Author

I created a C API Working Group decision issue.

All reactions

Sorry, something went wrong.

Uh oh!

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

encukou
encukou reviewed Nov 19, 2025
View reviewed changes
Comment thread Modules/_testcapimodule.c


static PyObject *
noop_eval(PyThreadState *tstate, struct _PyInterpreterFrame *f, int exc)

@encukou encukou Nov 19, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Doesn't _PyInterpreterFrame, need a public name too? Otherwise you can't quite use the functions without private API.

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Nov 19, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

To implement an eval function, you should likely use the internal C API (pycore_interpframe.h) to access frame members, you're right. I don't want to add _PyInterpreterFrame structure members to the PyUnstable API, it's too unstable :-D I prefer to leave it in the internal C API.

I don't think that it's worth it to expose struct _PyInterpreterFrame* type in the PyUnstable API. What do you think?

Sorry, something went wrong.

Uh oh!

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

All reactions

@encukou encukou Nov 19, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

These functions are rather useless without making _PyInterpreterFrame public. At least should be an opaque type, with a function to upgrade it to the full PyFrameObject.

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Nov 19, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The API changed in Python 3.11 to take a _PyInterpreterFrame* instead of a PyFrameObject*. It's basically only used by PyTorch Dynamo which already uses the internal C API:

https://github.com/pytorch/pytorch/blob/be33b7faf685560bb618561b44b751713a660337/torch/csrc/dynamo/eval_frame.c#L15-L17

I wouldn't say that this API is useless without a public API for _PyInterpreterFrame*. It's just "unusual" :-)

At least should be an opaque type, with a function to upgrade it to the full PyFrameObject.

It would make the code (way) slower, _PyInterpreterFrame* idea is to avoid creating a concrete Python object for a frame unless it's strictly needed. I suggest using the internal C API for _PyInterpreterFrame* instead.

Sorry, something went wrong.

Uh oh!

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

All reactions

@encukou encukou Nov 19, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I wouldn't say that this API is useless without a public API for _PyInterpreterFrame*.

What is the use, then?

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Nov 20, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@emmatyping @efimov-mikhail: Do you have an opinion on these questions?

Sorry, something went wrong.

Uh oh!

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

All reactions

@efimov-mikhail efimov-mikhail Nov 20, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

IMO, the main idea of this change is not really to make those functions public. We mark them as PyUnstable_ for sending clear message to its users: "we remember about those function, we don't want to change or remove them in the near future". One can use them and rely on their presence in C API, but can't rely on stability of _PyInterpreterFrame structure. So, there's a need to use some private headers in this case.

I agree that it's not the perfect position for us, but current situation isn't any better.
We have functions that both private and public.
They're private, because they have _Py* names.
But they're "kinda public", since PEP 523 is guaranteed their presence.
PyUnstable_ suits better for those semi-public functions.
But making _PyInterpreterFrame and all its members PyUnstable_ too seems redundant to me.

Sorry, something went wrong.

Uh oh!

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

emmatyping reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@encukou encukou Nov 24, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

But making _PyInterpreterFrame and all its members PyUnstable_ too seems redundant to me.

Same here. I think it should be opaque, and we should add (slow) a function to convert it to the full public PyFrameObject*.

That would make this usable without resorting to private API. Yes, doing that would be slow for the current users, so those will probably continue using the fully-private API -- but that's not the point.
If we expose PyUnstable_InterpreterState_GetEvalFrameFunc,

  • users should be able to use it (simple slow printf-based debugging is a valid use case), and
  • in CPython we should be able to test that you can use it without needing internal headers.

Or for a different point of view: really the issue solved here is that we don't want documented _Py-prefixed API.
That should apply to argument types too.

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Nov 25, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I created #141950 to add PyUnstable_InterpreterFrame_GetFrameObject().

Sorry, something went wrong.

Uh oh!

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

All reactions
encukou
encukou reviewed Nov 19, 2025
View reviewed changes
Comment thread Doc/c-api/init.rst Resolved

Uh oh!

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

@vstinner
_PyFrameEvalFunction changelog
c624f74
@vstinner vstinner mentioned this pull request Nov 25, 2025
gh-141518: Add PyUnstable_InterpreterFrame_GetFrameObject() function #141950
Closed
@vstinner
PyUnstable_InterpreterState_SetEvalFrameFunc() can now fail
8fd495b
@vstinner

vstinner commented Nov 28, 2025

Copy link
Copy Markdown
Member Author

PyUnstable_InterpreterState_SetEvalFrameFunc() can now fail, its return type is int (instead of void).

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Feb 10, 2026

Copy link
Copy Markdown
Member Author

The C API Working Group decided to not add a public function for this feature, but keep the _Py name instead: capi-workgroup/decisions#89.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner closed this Feb 10, 2026
@vstinner
vstinner deleted the eval_frame_func branch February 10, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou left review comments
@efimov-mikhail efimov-mikhail efimov-mikhail approved these changes
@emmatyping emmatyping emmatyping approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

awaiting merge topic-C-API

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.

4 participants

@vstinner @efimov-mikhail @encukou @emmatyping
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.