]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-124872: Replace enter/exit events with "switched" (#124776)
authorRichard Hansen <rhansen@rhansen.org>
Mon, 14 Oct 2024 19:28:41 +0000 (15:28 -0400)
committerGitHub <noreply@github.com>
Mon, 14 Oct 2024 19:28:41 +0000 (12:28 -0700)
commit843d28f59d2616d052d9d45f31823976da07f0f3
tree85ca3958261acfd6c320d1a306c1871b4993da6b
parente99650b80ace3893c2a80b3f2a4aca99cb305191
gh-124872: Replace enter/exit events with "switched" (#124776)

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, replace the enter and exit events with
a single switched event.

The former exit event was emitted just before exiting the context.
The new switched event is 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 event type can be added in the future.  It is not added here
because YAGNI.

I skipped 0 in the enum as a matter of practice.  Skipping 0 makes it
easier to troubleshoot when code forgets to set zeroed memory, and it
aligns with best practices for other tools (e.g.,
https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum).
Doc/c-api/contextvars.rst
Include/cpython/context.h
Lib/test/test_capi/test_watchers.py
Modules/_testcapi/watchers.c
Python/context.c
Tools/c-analyzer/cpython/ignored.tsv