Skip to content

Avoid duplicate AST initialization and lazy-import locals allocation - #9183

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:fix/ast-initialization-lazy-locals-315
Draft

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:fix/ast-initialization-lazy-locals-315

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Follow up on the two review findings in #9179 after its merge.

  • Let PyType::call invoke the AST initializer once. NodeAst::slot_new only allocates, matching CPython's PyType_GenericNew. This also preserves custom subclass initializers that deliberately omit super().__init__() and allocation-only direct __new__ calls.
  • Check existing frame-locals identity without materializing a fresh locals dictionary during ordinary eager imports. Keep the module-level check before the __lazy_modules__ lookup.

Only two Rust files change. No library copies, test expectations, or skip markers change.

Validation

Fresh release binary built from this follow-up on main 9f6f7719.

  • Eight bounded observations exactly match pinned CPython 3.15 d220409: abstract warning count, inherited field writes, custom/delegating initialization, and direct __new__ allocation.
  • Full canonical test_ast: 220 total, 205 pass, 9 skip, 6 existing expected failures.
  • Full canonical test_lazy_import: 161 total, 157 pass, 4 skip.
  • Corresponding pinned-CPython oracle suites pass.
  • Fresh workspace native tests: 1,373 pass across 22 targets.
  • Fresh C-API native tests: 123 pass, 4 existing ignored tests.
  • Strict workspace and C-API Clippy pass with -D warnings.

The existing missing-C-API skips and AST expected failures remain visible; these results do not claim complete AST or compiler parity.

Let type.__call__ own AST initialization, matching CPython generic allocation, and inspect existing frame locals without materializing them for lazy policy checks.

Assisted-by: OpenAI Codex:model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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.

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.

1 participant