cpython/Modules/_testcapi
Petr Viktorin 8923ca418c
gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925)
There are newly documented restrictions on tp_traverse:

    The traversal function must not have any side effects.
    It must not modify the reference counts of any Python
    objects nor create or destroy any Python objects.

* Add several functions that are guaranteed side-effect-free,
  with a _DuringGC suffix.
* Use these in ctypes
* Consolidate tp_traverse docs in gcsupport.rst, moving unique
  content from typeobj.rst there

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-08 09:15:11 +02:00
..
clinic
abstract.c
buffer.c gh-140557: Force alignment of empty bytearray and array.array buffers (GH-140559) 2026-01-26 16:45:17 +01:00
bytes.c gh-129813: Fix PyBytesWriter tests (#139892) 2025-10-10 13:01:06 +02:00
code.c
codec.c
complex.c
config.c
datetime.c
dict.c gh-141510: Test frozendict C API (#145081) 2026-02-21 17:00:23 +01:00
docstring.c
exceptions.c GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
file.c
float.c gh-143429: Use compile-time NaN encoding detection for test_struct (#143432) 2026-01-09 10:46:48 +00:00
frame.c
function.c gh-144629: Add test for the PyFunction_GetAnnotations() function (#144630) 2026-02-10 14:38:24 +00:00
gc.c
getargs.c
hash.c
heaptype.c gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925) 2026-04-08 09:15:11 +02:00
immortal.c gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (#145901) 2026-03-31 13:17:49 +00:00
import.c gh-142349: Implement PEP 810 - Explicit lazy imports (#142351) 2026-02-12 00:15:33 +00:00
list.c
long.c gh-147988: Initialize digits in long_alloc() in debug mode (#147989) 2026-04-02 11:55:34 +00:00
mem.c
modsupport.c gh-144175: Add PyArg_ParseArray() function (#144283) 2026-03-06 21:57:44 +00:00
module.c gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925) 2026-04-08 09:15:11 +02:00
monitoring.c gh-79315: Remove Include/pylock.h and Include/monitoring.h (#139731) 2025-10-08 00:49:24 +02:00
numbers.c
object.c gh-143300: implement PyUnstable_SetImmortal for marking objects as immortal (#144543) 2026-02-11 20:59:31 +05:30
parts.h gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556) 2025-11-05 12:31:42 +01:00
pyatomic.c
README.txt
run.c
set.c
structmember.c
time.c
tuple.c gh-111489: Add PyTuple_FromArray() function (#139691) 2025-10-10 08:54:12 +02:00
type.c
unicode.c Improve tests for the PyUnicodeWriter C API (GH-146157) 2026-03-19 19:15:30 +02:00
util.h
vectorcall.c GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
watchers.c gh-146615: Fix format specifiers in test cextensions (GH-146618) 2026-03-31 10:58:27 +03: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.