Summary
Group related CPython 3.15 list/tuple/slice search and comparison fixes in 534 changed lines across eight production Rust files:
-
Reuse the shared slice-index conversion for list/tuple index bounds, saturate oversized integers, convert both bounds before reading the current list length, and allow searches to reach elements appended by callbacks.
-
Retain raw bounds through conversion/search and release them in argument order through one shared owner, rather than writing method-specific argument parsers.
-
Use CPython's constant list.index/list.remove missing-value errors without invoking user formatting callbacks.
-
Preserve raw ordering results and exact comparison operators for lists, tuples and structseqs; compare tuple prefixes even when lengths differ.
-
Reuse the same raw-result comparison helper for slice components, preserve the same-slice shortcut, and retain the raw length through indices conversions and cleanup. Correct slice-specific conversion diagnostics and constructor keyword priority.
-
Release list element roots before observing callback mutations, then reload the first unequal pair for ordering. Preserve the existing constant-time identical-object equality shortcut.
-
Release detached list children in reverse and clear slice fields in step/start/stop order before freelisting, without retaining the old stop owner in a cached husk.
-
Preserve list.sort cleanup on key or comparison failure: reverse partial-key destruction, restore the current value permutation, restore the live list before reverse-releasing callback-added items, and preserve the original error over a mutation error.
-
Use initial/final reversal around the existing stable forward sort for reverse=True, releasing keys before the final value reversal even on failure.
-
Release each temporary repr result before the next callback. Slice repr reuses the corrected collection formatter also used by tuple/set/deque.
Reference and validation
Compared against CPython source commit d220409a13b77de7a6c30abe16ea90db01528edc and a verified CPython 3.15 oracle. 10,438 reference/model assertions and 82 additional independent oracle assertions passed, including mutation, finalizer order, argument conversion, descriptors, oversized bounds, and nonboolean comparison results. These are CPython/source-model checks, not execution of the Rust implementation.
Independent source review passed for the original six-file composition and the subsequent slice extension. Ordinary commit hooks passed. Focused host-env/VM/stdlib threading cargo check and normal all-targets Clippy passed on the final source. The final slice composition also exposes eight unchanged host_env/socket diagnostics in addition to the earlier four baseline diagnostics (one POSIX needless-collect and three ElementTree lints); no candidate-file warnings remain. Strict -D warnings is not clean because of that baseline; no warnings were suppressed. The compiler caught an owning-versus-borrowed method-resolution error before publication; the one-line explicit borrowed call was independently re-reviewed, normally committed, and rechecked.
The slice extension additionally passed 6,884 CPython/source-model assertions and 109 independent CPython assertions. These reference checks do not claim RustPython runtime coverage.
No Python, Lib, tests, markers or workflows are changed. This does not remove existing expected failures or claim they have passed.
The lifecycle extension additionally passed 59 focused CPython assertions, 40 teardown/structseq controls and 90 independent reference assertions. These include explicit negative controls for deferred behavior, not claims that every probed behavior is fixed. Independent source review passed on the final three-file extension. The first check caught a missing formatter import; it was corrected before the final validation rerun. The final lifecycle source passed threaded cargo check in 1m00s and all-targets Clippy in 2m17s. That exact branch produced the four unchanged POSIX/ElementTree diagnostics, matching the recorded four-warning baseline; the later-main socket diagnostics are absent on this branch. No warnings were suppressed.
Limits and integration
Native RustPython execution was not performed because the required execution guard has not been verified. Full workspace/C-API tests and cross-platform runtime checks remain unrun; hosted CI is pending. Separately locked cross-thread snapshots and malformed-call cleanup before shared bound binding remain inherited limitations. slice.indices retains its inherited shared-binder arity/keyword wording and precedence; typed raw arguments preserve signature metadata and prevent conversion before binding without adding a method-specific parser.
Old infrastructure PRs #8966, #8944, #8939 and #8848, plus metadata PR #9551, touch some of these files but do not implement these behavior fixes. Their eventual composition may require textual reconciliation. The changed public Rust helper/trait interfaces may also affect out-of-tree consumers; all in-tree consumers were checked.
Generic tuple child teardown remains unchanged: structseq shares the Rust tuple payload but CPython destroys its fields forward, unlike ordinary tuples. Tuple-construction allocation-boundary cleanup, subclass dictionary/slot-before-payload teardown, sort mutation-counter false positives for no-op mutations, and algorithm-specific comparison traces or exact failure permutations remain outside this patch. The existing sorting algorithm is not replaced. Old algorithm PR #6096 must preserve these driver/lifecycle controls when composed. The GC designs in #8939/#8944 retain clear-return, edge destruction, then freelist insertion; no core GC rewrite is included.
AI-assisted contribution by OpenAI Codex; assistance is disclosed in the commit trailer.