Implement the sentinel builtin (PEP 661) - #8945
youknowdot wants to merge 1 commit into
Conversation
Add unique sentinel values with copy/pickle identity, caller module capture, union support, and cycle collection. Compare constructor behavior and six upstream tests with CPython v3.15.0rc2; retain the existing Python target and bundled libraries. Assisted-by: Codex:model-version-unavailable
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
| # Sentinel cases copied unchanged from CPython v3.15.0rc2 Lib/test/test_builtin.py. | ||
| # https://github.com/python/cpython/blob/v3.15.0rc2/Lib/test/test_builtin.py |
There was a problem hiding this comment.
When RustPython decides to target CPython 3.15 (rather than CPython 3.14), the file in question will be updated by a semi-automated process.
There was a problem hiding this comment.
this can be simply replaced by test_builtin. so removing will be fine
Summary
Implement the native
sentinel(name, /, *, repr=None)builtin described by PEP 661, as an independent prerequisite for the Python 3.15 standard-library migration.__name__, writable/deletable__module__, copy/deepcopy identity, and name-based pickle reduction.This branch is based directly on RustPython
ada43c4f82b9df4e260f1368038c31cd55c4a61e. It contains only the native sentinel implementation and its snippet. It does not change the advertised Python version, standard-library sources, import machinery, compile/module behavior, or generated workflows.Reference and attribution
Behavior was compared with CPython v3.15.0rc2, commit
435c9e5a798c99653e3ab64ce29baed0e4f3dfee:The six
test_sentinel*methods are copied from that CPython test source; their assertions and AST semantics are preserved. Additional edge tests cover module capture, self/mutual/repr GC cycles, string subclasses, Unicode, signature/documentation, and identity/protocol behavior.Validation
All commands below use the independent branch and its unchanged 3.14
Lib:cargo build --locked --release --features sqlite: passedrustpython -m test test_builtin test_types test_gc test_pickle: all four modules passed; 1,341 tests run, 104 skippedcpython-314, andsite,importlib, andtest.supportall loaded from this branch'sLibgit diff --check: passedThe full snippet aggregate (
pytest -v --timeout=60, CPython 3.14.7 plus the isolated RustPython binary) reports 469 passed, 13 failed. It is not a green aggregate result:PermissionErrorwhere this sandbox returnsEINVALBoth sentinel harness cases and both SQLite cases pass. The CPython 3.14 sentinel harness case validates the version guard, while the separate 3.15rc2 run executes all 12 tests. All failing test source files are unchanged.
The remaining isolated-branch Rust checks also pass:
GitHub CI, CodSpeed, and pyperformance currently require maintainer approval for this fork; they have not run. This remains a draft for review.
Limitations
This change adds the runtime builtin and union support; it does not claim complete Python 3.15 compatibility or add third-party static type-checker support. Validation is on Linux x86_64; other platforms have not been exercised here.
AI assistance
OpenAI Codex assisted with implementation, CPython comparison, tests, review, and this PR description under maintainer direction. The runtime did not expose the exact model version. Reported checks are automated Linux x86_64 verification; no additional human-use or untested-platform verification is claimed.