Skip to content

[3.14] gh-158102: Add tests for the slice C API (GH-158120) - #158292

Merged
serhiy-storchaka merged 1 commit into
python:3.14from
serhiy-storchaka:backport-8c056c3-3.14
Sep 29, 2026
Merged

serhiy-storchaka merged 1 commit into
python:3.14from
serhiy-storchaka:backport-8c056c3-3.14

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Test PySlice_Check(), PySlice_New(), PySlice_GetIndices(), PySlice_Unpack(), PySlice_AdjustIndices() and PySlice_GetIndicesEx().

PySlice_GetIndicesEx() is tested both as a macro and as a deprecated function, including the case when __index__() resizes the sequence whose size is passed as the length: the macro evaluates it after PySlice_Unpack(), the function before the call.

(cherry picked from commit 8c056c3)

The conflicts were only in the registration lists, which have diverged from main: Modules/Setup.stdlib.in, Modules/_testlimitedcapi.c, Modules/_testlimitedcapi/parts.h and the two PCbuild files. Modules/_testlimitedcapi has no slots.c here, so slice.c is registered between set.c and sys.c, and the registration calls are in PyInit__testlimitedcapi(), which returns PyObject *, so the new check returns NULL instead of -1.

In Modules/_testlimitedcapi/slice.c, Py_TARGET_ABI3T does not exist in 3.14 -- there is no Include/pyabi.h -- so the limited C API is simply not tested in a free-threading build, like in the other files of Modules/_testlimitedcapi.

Test PySlice_Check(), PySlice_New(), PySlice_GetIndices(), PySlice_Unpack(),
PySlice_AdjustIndices() and PySlice_GetIndicesEx() -- both the macro and the
deprecated function.

Document the length and step precondition of PySlice_AdjustIndices()
(cherry picked from commit 8c056c3)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@serhiy-storchaka
serhiy-storchaka merged commit fe0482a into python:3.14 Sep 29, 2026
53 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the backport-8c056c3-3.14 branch November 25, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant