Skip to content

Preserve missing caller modules in eager type aliases - #9073

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-typealias-eager-module
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-typealias-eager-module

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extract the independent eager-alias module lookup guard from #8954. When caller globals have no __name__, an eagerly constructed TypeAliasType must report __module__ is None without consulting its stored value.

RustPython shares a storage field between lazy evaluation functions and eager values. Restricting its fallback to lazy aliases restores the existing Python 3.14 contract. This does not include Python 3.15 qualified names or writable alias modules.

Reference and coverage

CPython 3.14.7 and 3.14.8 eager constructors have no evaluation function. Their module getter therefore never reads the aliased value's attributes.

The existing typing snippet gains two focused cases with missing caller module: an ordinary int value and a value whose module descriptor records accesses. They verify None and no descriptor calls. Existing canonical missing-module coverage uses a lazy type statement, so it does not catch this eager case.

  • Independent source/diff review and duplicate checks against current main and relevant open/published PRs.
  • Complete typing snippet passes on CPython 3.14.7 and 3.14.8; the previous native RustPython binary fails the new missing-module assertion.
  • Patched native build, complete snippet, selected CPython/native pytest, and unchanged canonical type-alias cases.
  • Normal commit hooks; VM and separately configured C-API Clippy with warnings denied.

Local validation is bounded Linux coverage; the full hosted matrix remains required. Existing lazy-fallback error suppression and caller-globals lookup behavior are unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Eager type aliases without an explicitly provided module now report None for their module instead of inheriting one from the value they represent.
    • Creating these aliases no longer accesses the value’s module property, avoiding unintended side effects.

Only lazy aliases may obtain their module from the evaluation function. Eager aliases without a caller __name__ must not inspect their stored value.

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

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3a11a2f3-035e-4e62-975c-005df3e4a692

📥 Commits

Reviewing files that changed from the base of the PR and between 9d6bf4d and f283fbd.


📒 Files selected for processing (2)
  • crates/vm/src/stdlib/_typing.rs
  • extra_tests/snippets/stdlib_typing.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.



📝 Walkthrough

Walkthrough

The TypeAliasType.__module__ fallback now applies only to lazy aliases. A regression test checks that eager aliases without a caller module return None and do not access the value’s __module__ property.

Changes

TypeAliasType module handling

Layer / File(s) Summary
Restrict module fallback and test eager aliases
crates/vm/src/stdlib/_typing.rs, extra_tests/snippets/stdlib_typing.py
The __module__ fallback now applies only to lazy aliases. Tests check eager aliases created with a built-in type and an object whose __module__ property records access.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: youknowone


Merge Risk: ⚪ Minimal · up to f283f

The change is narrowly scoped to eager type-alias module handling, with regression cases for missing caller modules. No actionable merge-blocking risk is evident from the supplied changes.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving missing caller modules for eager type aliases.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ 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.

@youknowone
youknowone marked this pull request as ready for review October 10, 2026 14:34
@youknowone
youknowone enabled auto-merge (squash) October 10, 2026 14:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

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 ✅ Completed 2026-10-10T14:37:38.609361Z f283fbd 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f283fbdb23

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
// Fall back to compute_value's __module__ (like PyFunction_GetModule)
if let Ok(module) = self.compute_value.get_attr("__module__", vm) {
if self.is_lazy

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required AI-assistance trailer

The reviewed commit is authored and committed by Codex <codex@openai.com>, but its commit message contains no Assisted-by: AGENT_NAME:MODEL_VERSION trailer. Because this is definitively AI-assisted, the commit does not satisfy the repository's critical disclosure policy and needs the required trailer before it can land.

AGENTS.md reference: AGENTS.md:L20-L23

Useful? React with 👍 / 👎.

Comment on lines +85 to +86
assert alias_namespace["alias"].__module__ is None
assert alias_module_lookups == []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the forbidden test additions

This new block adds assertions and support logic to a test file, but the repository's critical test-modification policy forbids modifying test logic or assertions and limits acceptable test-file changes to expected-failure marker updates. This coverage therefore cannot be landed in this file under the current policy; remove or relocate it, or obtain a policy change first.

AGENTS.md reference: AGENTS.md:L273-L279

Useful? React with 👍 / 👎.

@youknowone
youknowone merged commit 4485801 into RustPython:main Oct 10, 2026
21 checks passed
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