Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Dec 29, 2025

related to #6548

Summary by CodeRabbit

  • New Features
    • Frame objects now expose a new attribute to access their builtins dictionary from Python.
    • The sys module now includes a new attribute that provides a frozen set of standard library module names.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds Frame.f_builtins getter exposing a frame's builtins dict and adds sys.stdlib_module_names attribute returning a frozen set of standard-library module names; also updates cspell dictionary with four new words.

Changes

Cohort / File(s) Summary
Frame Type Extension
crates/vm/src/builtins/frame.rs
Added a #[pygetset] f_builtins(&self) -> PyDictRef method that returns self.builtins.clone() to expose the frame builtins to Python.
Sys Module Extension
crates/vm/src/stdlib/sys.rs
Added STDLIB_MODULE_NAMES constant and #[pyattr(once)] fn stdlib_module_names(vm: &VirtualMachine) -> PyObjectRef that returns a PyFrozenSet of stdlib module names; exported PyFrozenSet in imports.
Spell Dictionary Update
.cspell.dict/cpython.txt
Added four new tokens: lsprof, multibytecodec, pydecimal, pyrepl.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰
I hopped through frames with eager paws,
Found builtins hidden behind the gauze.
A frozen list of modules bright,
Now tucked within sys's moonlight.
Hooray — inspectors cheer my cause!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'stdlib_module_names' directly matches the primary feature added: a new sys.stdlib_module_names attribute that exposes standard library module names.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1362df and 2538f7b.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_sys.py is excluded by !Lib/**
📒 Files selected for processing (3)
  • .cspell.dict/cpython.txt
  • crates/vm/src/builtins/frame.rs
  • crates/vm/src/stdlib/sys.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.

❤️ Share

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

@youknowone youknowone marked this pull request as ready for review December 29, 2025 05:26
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
crates/vm/src/stdlib/sys.rs (1)

446-452: Consider using .expect() instead of .unwrap() for better diagnostics.

The implementation correctly creates a frozen set of standard library module names. The .unwrap() call is safe in this context since all items are strings (which are hashable), but using .expect() with a descriptive message would provide better diagnostics if this ever fails unexpectedly.

🔎 Optional improvement
 #[pyattr(once)]
 fn stdlib_module_names(vm: &VirtualMachine) -> PyObjectRef {
     let names = STDLIB_MODULE_NAMES
         .iter()
         .map(|&n| vm.ctx.new_str(n).into());
-    PyFrozenSet::from_iter(vm, names).unwrap().to_pyobject(vm)
+    PyFrozenSet::from_iter(vm, names)
+        .expect("stdlib_module_names should always be hashable")
+        .to_pyobject(vm)
 }
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 476b75d and e1362df.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_sys.py is excluded by !Lib/**
📒 Files selected for processing (2)
  • crates/vm/src/builtins/frame.rs
  • crates/vm/src/stdlib/sys.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style by running cargo fmt to format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • crates/vm/src/builtins/frame.rs
  • crates/vm/src/stdlib/sys.rs
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-27T14:03:49.011Z
Learning: RustPython is a Python 3 interpreter written in Rust implementing Python 3.13.0+ compatibility with complete Python environment in Rust (not CPython bindings), clean implementation without compatibility hacks, and cross-platform support including WebAssembly compilation
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.

Applied to files:

  • crates/vm/src/stdlib/sys.rs
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.

Applied to files:

  • crates/vm/src/stdlib/sys.rs
🪛 GitHub Check: Check Rust code with clippy
crates/vm/src/stdlib/sys.rs

[warning] 218-218:
Unknown word (pyrepl)


[warning] 215-215:
Unknown word (pydecimal)


[warning] 203-203:
Unknown word (multibytecodec)


[warning] 199-199:
Unknown word (lsprof)

🔇 Additional comments (3)
crates/vm/src/builtins/frame.rs (1)

44-47: LGTM! Clean implementation of frame.f_builtins.

The getter correctly exposes the frame's builtins dictionary and follows the same pattern as f_globals. This aligns with Python's frame object interface.

crates/vm/src/stdlib/sys.rs (2)

12-13: LGTM! Necessary import for stdlib_module_names implementation.

Adding PyFrozenSet to the imports is required for the new stdlib_module_names attribute.


152-444: LGTM! Comprehensive standard library module list.

The constant list matches CPython's standard library modules. Note that the static analysis warnings about "unknown words" (pyrepl, pydecimal, multibytecodec, lsprof) are false positives—these are valid Python standard library module names.

@youknowone youknowone merged commit feb5066 into RustPython:main Dec 29, 2025
1 check passed
@youknowone youknowone deleted the stdlib_names branch December 29, 2025 12:43
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