cpython/Modules/_testcapi
Kirill Podoprigora bee112a94d
gh-124872: Replace enter/exit events with "switched" (#125532)
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).

Co-authored-by: Richard Hansen <rhansen@rhansen.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-10-16 13:53:21 +02:00
..
clinic
abstract.c gh-105201: Add PyIter_NextItem() (#122331) 2024-08-08 00:47:15 +02:00
buffer.c
bytes.c gh-121645: Add PyBytes_Join() function (#121646) 2024-08-30 12:57:33 +00:00
code.c
codec.c gh-111495: Add tests for PyCodec_* C API (#123343) 2024-09-29 15:22:39 +00:00
complex.c
config.c gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472) 2024-09-02 23:25:08 +02:00
datetime.c gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125194) 2024-10-09 17:15:23 +02:00
dict.c gh-124296: Remove private dictionary version tag (PEP 699) (#124472) 2024-10-01 12:39:56 -04:00
docstring.c
exceptions.c gh-121040: Use __attribute__((fallthrough)) (#121044) 2024-06-27 09:58:44 +00:00
file.c
float.c
gc.c Replace PyObject_Del with PyObject_Free (#122453) 2024-08-01 14:12:33 +02:00
getargs.c
hash.c gh-122854: Add Py_HashBuffer() function (#122855) 2024-08-30 15:42:27 +00:00
heaptype.c gh-124153: Implement PyType_GetBaseByToken() and Py_tp_token slot (GH-124163) 2024-09-18 09:18:19 +02:00
immortal.c
list.c
long.c gh-116560: Add PyLong_GetSign() public function (#116561) 2024-06-03 14:06:31 +02:00
mem.c
monitoring.c gh-118692: Avoid creating unnecessary StopIteration instances for monitoring (#119216) 2024-05-21 20:42:51 +00:00
numbers.c gh-111495: Add tests for PyNumber C API (#111996) 2024-08-26 15:59:22 +02:00
object.c gh-118789: Add PyUnstable_Object_ClearWeakRefsNoCallbacks (#118807) 2024-06-18 09:57:23 -04:00
parts.h gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472) 2024-09-02 23:25:08 +02:00
pyatomic.c gh-121368: Fix seq lock memory ordering in _PyType_Lookup (#121388) 2024-07-08 14:52:07 -04:00
README.txt
run.c Fix typos in docs, error messages and comments (#123336) 2024-08-28 14:41:04 +03:00
set.c
structmember.c
time.c
tuple.c gh-111495: Add tests for PyTuple C API (#118757) 2024-08-26 11:57:52 +02:00
unicode.c gh-119182: Add PyUnicodeWriter_WriteUCS4() function (#120849) 2024-06-24 17:40:39 +02:00
util.h gh-111495: Add tests for PyCodec_* C API (#123343) 2024-09-29 15:22:39 +00:00
vectorcall.c gh-121791: Check for NULL in MethodDescriptor2_new in _testcapi (#121792) 2024-07-16 11:29:33 +03:00
watchers.c gh-124872: Replace enter/exit events with "switched" (#125532) 2024-10-16 13:53:21 +02:00

Tests in this directory are compiled into the _testcapi extension.
The main file for the extension is Modules/_testcapimodule.c, which
calls `_PyTestCapi_Init_*` from these functions.

General guideline when writing test code for C API.
* Use Argument Clinic to minimise the amount of boilerplate code.
* Add a newline between the argument spec and the docstring.
* If a test description is needed, make sure the added docstring clearly and succinctly describes purpose of the function.
* DRY, use the clone feature of Argument Clinic.
* Try to avoid adding new interned strings; reuse existing parameter names if possible. Use the `as` feature of Argument Clinic to override the C variable name, if needed.