Skip to content

Align AST construction and replacement with Python 3.15 - #9272

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/ast-construction-315
Oct 22, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/ast-construction-315

Conversation

@youknowone

Copy link
Copy Markdown
Member

Summary

Extract the native AST construction/replacement closure from #8954 onto current main, without parser, PEP 798, schema or library changes.

  • Validate _field_types when constructor fields remain, while keeping fully supplied and fieldless custom nodes valid.
  • Apply list defaults only to exact GenericAlias instances, matching CPython.
  • Preserve lone-surrogate field names in declaration-ordered missing-argument errors.
  • Register generated __replace__ methods through the existing shared argument handler, including its positional-argument diagnostic.

Only _ast/python.rs and _ast/pyast.rs change. Existing canonical test bodies, assertions and expected-failure markers are untouched; no duplicate snippets or Python-behavior Rust tests are added. This does not depend on Ruff #7.

Verification

Source reviewed against CPython 3.15.0 at d220409a13b77de7a6c30abe16ea90db01528edc.

Linux rebuilds of both main cf56c1fa and the candidate ran the same 22 selected canonical constructor/replacement methods separately: 20 passed and the same two existing expected failures remained. The corresponding 22 methods passed on pinned CPython. These selections are regression guards, not direct proof of the specific semantic changes.

Eight bounded external observations, using ordinary Python objects, compared exact baseline/candidate/oracle outcomes, messages and codepoints. The candidate fixes the observed GenericAlias subclass, surrogate-name and positional-replacement differences exactly; four controls remain unchanged. A non-dict _field_types now raises SystemError rather than succeeding. Its message deliberately omits CPython's implementation-specific Objects/dictobject.c:2620: prefix, so exact-message parity is not claimed for that case.

The exact candidate also passed threading and no-threading VM library checks, workspace and separately configured CAPI test compilation (--no-run), both strict all-target Clippy gates (-D warnings), and the configured applicable hooks. Workspace gates exclude wasm, venvlauncher and the separately checked CAPI. All 3,631 tracked source/symlink entries matched the recorded candidate manifest after validation. Build caches were reused; no clean-cache build is claimed.

Validation is bounded. No full AST/native suite, recursive-copy stress, broad pickle sweep, malformed-bytes crash-prevention case, no-threading runtime or non-Linux validation is claimed. Tests used one Cargo job, no incremental compilation, process limits and time/resource guards. No runtime guard fired.

Integration note

#8944 changes these AST files for interpreter-local class architecture. This extraction does not duplicate that work, but its method-registration hunks may need textual reconciliation if that PR lands later.

AI assistance

Prepared, extracted, source-reviewed and validated with OpenAI Codex (model version unavailable), for maintainer-requested Python 3.15 upgrade work. Validation described above is automated; no human manual-use verification is claimed.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 557c0686-c411-4eab-a276-93bee5691425
📥 Commits

Reviewing files that changed from the base of the PR and between 2be9389 and 2e1b9bf.

📒 Files selected for processing: 2
  • crates/vm/src/stdlib/_ast/pyast.rs
  • crates/vm/src/stdlib/_ast/python.rs
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. - Tom Cargill |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Validate missing-field metadata, recognize exact generic aliases for list
field defaults, and preserve surrogate names in ordered constructor errors.
Route generated AST replacement methods through the shared argument handler.

Extract the native closure from the 3.15 integration without parser/schema
changes or new library copies. Existing canonical tests remain unchanged.

Assisted-by: OpenAI Codex:model-version-unavailable
@youknowdot
youknowdot force-pushed the split/ast-construction-315 branch from ca913bb to 2e1b9bf Compare October 21, 2026 16:14
@youknowone
youknowone marked this pull request as ready for review October 22, 2026 02:18
@youknowone
youknowone merged commit aba1f5c into RustPython:main Oct 22, 2026
20 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-22T02:18:58.150727Z 2e1b9bf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants