Fix __origname__ of frozen modules by youknowone · Pull Request #6613 · RustPython/RustPython
Caution
Review failed
The pull request is closed.
📝 Walkthrough
Walkthrough
This pull request implements proper __origname__ metadata for frozen modules. A new public function resolve_frozen_alias maps internal frozen module alias names to their original counterparts, which is then used to correctly populate the __origname__ attribute during module initialization across the import and module systems.
Changes
| Cohort / File(s) | Summary |
|---|---|
Alias Resolution Function crates/vm/src/vm/mod.rs |
Adds public resolve_frozen_alias(name: &str) -> &str function that maps internal frozen module aliases ("_frozen_importlib" → "importlib._bootstrap", "_frozen_importlib_external" → "importlib._bootstrap_external") to their original names; includes a test validating the alias resolution behavior (test appears duplicated in file). |
Import Flow Updates crates/vm/src/import.rs |
Reworks import_frozen to fetch frozen objects directly from vm.state.frozen and construct code objects via vm.ctx.new_code; applies resolve_frozen_alias to derive the correct __origname__ attribute value instead of using the internal module name directly. |
Frozen Module Resolution crates/vm/src/stdlib/imp.rs |
Exposes resolve_frozen_alias as a public re-export; updates find_frozen to resolve the origname via resolve_frozen_alias and convert the result to a Python string. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
🐰 With frozen modules once unnamed,
Now aliases resolve their shame!
origname shines bright and true,
Bootstrap paths shine right on through!
✨ Finishing touches
- 📝 Generate docstrings
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
crates/vm/src/import.rscrates/vm/src/stdlib/imp.rscrates/vm/src/vm/mod.rs
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 @coderabbitai help to get the list of available commands and usage tips.