Repository navigation
Implement PEP 798 comprehension unpacking - #9342
Conversation
Extract the remaining Python 3.15 comprehension unpacking implementation from the integration branch. Use existing list/set/dict update operations and an explicit inner iterator loop for generator unpacking. Align the public DictComp AST representation and schema with CPython. Migrate test_unpack_ex and test_unparse with scripts/update_lib from CPython d220409a13b77de7a6c30abe16ea90db01528edc. Preserve existing Rust tests; add no duplicate regression tests or snippets. AI-assisted source extraction, canonical migration, and independent source review with OpenAI Codex. Runtime validation is not yet complete. Assisted-by: OpenAI 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 |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_exceptions.py (TODO: 1) dependencies: dependent tests: (no tests depend on exception) [x] lib: cpython/Lib/ast.py dependencies:
dependent tests: (164 tests)
[x] test: cpython/Lib/test/test_unpack.py dependencies: dependent tests: (no tests depend on unpack) Legend:
|
Remove the 40 newly added tests that compile Python source and assert Python-visible compiler behavior, following the Python-behavior test placement policy. The deletion is a net 1160 lines. Preserve the entire existing main test module byte-for-byte and leave all production code unchanged, including the production changes owned by RustPython#9342. Canonical Python suites have topic-level overlap, not proven one-to-one coverage of every removed oracle case; no equivalent coverage claim or test translation is made. Bounded locked/offline codegen --tests cargo check and strict Clippy passed. These compile test targets only; no tests or runtime were executed. Assisted-by: OpenAI Codex:model version unavailable
…n tests Normalize six supported comprehension-unpacking diagnostics using existing parser context. Restrict the dictionary-spread hint to its first entry to avoid changing unrelated diagnostics. Migrate the whole test_exceptions module from CPython d220409a13b77de7a6c30abe16ea90db01528edc with the existing updater, preserving only its two existing RustPython markers. Ruff sources and dependency pins are unchanged. Six focused check/build/strict Clippy gates passed. A paired 34-input compile-only comparison retains six canonical diagnostic improvements, with eight of fifteen canonical cases still differing; this is not full test_exceptions or CI validation.
Use exact retained AST and error ownership to normalize the remaining CPython 3.15 unpacking diagnostics. Reparse only the owned call argument slice with the unchanged Ruff parser when its original recovery loses generator clauses. Validated all 30 canonical compile-only cases in exec and doctest-style single modes against CPython 3.15.0, plus finite surrounding controls. Targeted compiler Clippy and source-bound builds passed. Full CI is pending. Cspell alone was omitted with the maintainer’s explicit one-commit approval because its npm bootstrap downloads returned HTTP 403; all other applicable configured commit hooks ran. AI assistance: dot authored, reviewed, and validated the changes. The runtime does not expose its exact model version. Assisted-by: dot: model version not exposed
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Split the PEP 798 implementation from #8954.
Current draft status
This PR implements RustPython's AST/compiler execution support, not a new Ruff grammar implementation. Ruff upstream completed comprehension unpacking in astral-sh/ruff#25104, released in 0.15.14. The Ruff revision already on RustPython main (
9290a8849542134d83f77e9360e7f0b93897fd93) parses the valid list, set, dictionary, and generator-expression forms. Waiting for upstream PEP 798 support or upgrading to Ruff 0.17.2 is not necessary for those forms.Hosted correctness CI for
247eb615failed in the CPython test jobs on Linux, macOS, Windows, and WASI; their build and snippet steps passed. The Linux log identifies two failing modules:test_exceptionsretains the obsolete expectation that[*x for x in xs]raisesSyntaxError, andtest_unpack_exhas fourteen malformed-input diagnostic mismatches. These are canonical-test migration and CPython-compatible error-message/location gaps, not missing valid-syntax parsing.The successor candidate now migrates
test_exceptions.pyas a whole canonical file through the existingscripts/update_libworkflow and adds a narrow RustPython-side normalization of existing parser diagnostics. Ruff source, its Cargo revision, and Cargo.lock are unchanged. The full warning/type-comment producer extension in RustPython/ruff#7 is not required. The latest follow-up fixes all eight remaining malformed-input canonical diagnostics in finite local comparisons; all 30 canonical exec/doctest-mode records now match CPython. Correctness CI for the latest commitddc36651932bf9f3a3836e23e1085ca364e25870passed all 24 jobs, and Lib Dependencies Check passed. Surrounding malformed inputs retain the known finite-comparison differences documented below. Whole-file migration also brings other exception/location and resource-sensitive cases; the completetest_exceptionsmodule has not been runtime-validated locally. No selective method copies or new skips/xfails were introduced.Changes
DictUpdate.test_unpack_ex.py,test_unparse.py, andtest_exceptions.pyas whole canonical files usingscripts/update_lib, pinned to CPythond220409a13b77de7a6c30abe16ea90db01528edc.The Ruff revision already on main parses these forms: starred comprehension elements use
Expr::Starred, while dictionary unpacking usesExprDictCompwith no key. This PR implements the RustPython AST/compiler side. It does not change Ruff, VM instruction definitions, unrelated compiler location handling, or interpreter lifecycle code. No custom tests or snippets are added.Historical validation
Validated original commit:
247eb615c61e3f167245d55618fbfad611b5fd37.cargo check --offline --locked -p rustpython-codegen -p rustpython-vm --libpassed.cargo clippy --offline --locked -p rustpython-codegen -p rustpython-vm --lib -- -D warningspassed.cargo build --offline --locked --bin rustpythonsucceeded. The exact Cargo artifact was independently copied and sealed with its committed standard library.test_unpack_exdoctest segments passed under ordinary checkers. Their raw output matched pinned CPython exactly.send()behavior.The full
test_unpack_exmodule and broader parser, lifecycle, GC and fuzz suites were not run locally. Local validation used the unchanged commit above; a source-only merge check against main5bccf31156996d42882485ba70f17edbc77a713ewas conflict-free and retained the same nine-file patch.Historical successor local validation (partial)
Validated candidate tree:
21011e3035c2f5cce41935d2bd719e274212fb5e(successor of247eb615; separate from the historical results above). Final local commit:6ff465bd7c678c94ce455e7f35ca51e5b166b52d, treebe9bba0359348c12c2ac366aeca31b2d7cc5148f. Normal commit hooks passed. The final tree differs from the validated tree only by two source-reviewed, token-equivalent rustfmt line wraps; the six build gates and paired runtime checks below were run before that formatting-only change, not rerun on the final commit.d220409a13b77de7a6c30abe16ea90db01528edc. No compiled case bytecode was executed; canonical expected messages were unchanged.The whole-file
test_exceptionsupdate is included but its full runtime suite was not run. No full-suite success, global non-regression, or green successor CI is claimed. This PR remains a draft.Historical mapping-rest CI follow-up (RustPython only; Ruff unchanged)
SyntaxErrorTests.test_encodingsexpected-failure marker through the existing whole-fileupdate_lib --patchesworkflow. Linux, macOS, and Windows CI all reported this test as an unexpected success. Preserve the existing Windows-onlytest_windows_messagemarker; add no skip or expected failure.Validation:
d220409a13b77de7a6c30abe16ea90db01528edc). The two CI mapping cases now match CPython exactly; all 34 previous unpacking-diagnostic results are unchanged.SyntaxError.textserialization adds a trailing newline that CPython omits. The strict comparison and this residual are retained, not relaxed or hidden by dropping the case.Unpacking diagnostic follow-up
Validated commit:
ddc36651932bf9f3a3836e23e1085ca364e25870.-D warnings) passed. Validation progressed through successive 71-, 85-, and 98-input compile-only comparisons, retaining earlier inputs and prior binaries/results. No previously matching control regressed. The final candidate fully matches 63/98 inputs versus 59/98 for the validated call-generator checkpoint. In that comparison, five rows changed: four fully match CPython; the multiline/comment control now has the correct message and positions but retains the existing serializer's extra LF inSyntaxError.text. The earlier comment-key LF residual also remains. Comparisons use raw fields without normalization.Commit-hook limitation: cspell alone was omitted for this commit with the maintainer’s explicit one-time approval because its configured npm bootstrap downloads returned HTTP 403. Cspell has not passed. The normal pre-commit hook ran: merge-conflict and rustfmt checks passed; other configured hooks had no applicable files. Hosted correctness CI for this exact commit completed successfully on 2026-10-27 at 02:50 UTC (24/24 jobs); Lib Dependencies Check also passed.