Open rhansen opened 17 hours ago
Generally, it's a bad idea to create several different PRs for the same issue -- you can put all the needed changes in the same PR.
Apologies—I was under the impression that this project squashes pull requests when merging, which I don't want (the commits are intended to be separate). I can combine them into a single PR if that would be preferred.
We do squash, but why do you want the commits to be separate? It's harder to review and backport across multiple PRs
Feature or enhancement
Proposal:
(split off of https://github.com/python/cpython/issues/99633#issuecomment-2380302948 to keep related pull requests and discussion better organized)
Starting in v3.14, C code can subscribe to "context enter" and "context exit" events:
https://github.com/python/cpython/blob/120729d862f0ef9979508899f7f63a9f3d9623cb/Include/cpython/context.h#L30-L60
See gh-119333 for some background.
I would like to replace the just-added "context enter" and "context exit" events with a single "context switched" event:
Rationale: Users want to know when the current context switches to a different context object. Right now this happens when and only when a context is entered or exited, so the enter and exit events are synonymous with "switched". However, if the changes proposed for gh-99633 are implemented, the current context will also switch for reasons other than context enter or exit. Since users actually care about context switches and not enter or exit, replacing the enter and exit events with a single switched event would make the new feature compatible with gh-99633.
The current "context exit" event is emitted just before exiting the context. The new "context switched" event would be emitted after the context is exited to match the semantics users expect of an event with a past-tense name. If users need the ability to clean up before the switch takes effect, another "context is about to switch" event can be added in the future. I am not proposing to add such an event for this issue because no users have requested it yet (YAGNI).
I would love to get this resolved before v3.14 is released so that we don't have to worry about breaking backwards compatibility.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on another bug report.
Links to previous discussion of this feature:
https://github.com/python/cpython/issues/99633#issuecomment-2380302948
Linked PRs