correct builtins type under function by youknowone · Pull Request #6745 · RustPython/RustPython
📝 Walkthrough
Walkthrough
The changes refactor PyFunctionNewArgs struct field signatures, converting OptionalArg types to Option, renaming defaults to argdefs, and enhance builtins resolution logic to fallback to vm.builtins.dict() with module unwrapping. The py_new constructor is updated to validate closure length against code.freevars. A test is added to verify that function \builtins resolves to a dict.
Changes
| Cohort / File(s) | Summary |
|---|---|
PyFunction signature and constructor updates crates/vm/src/builtins/function.rs |
PyFunctionNewArgs struct fields refactored: defaults renamed to argdefs, types changed from OptionalArg to Option; closure and kwdefaults similarly updated. py_new constructor adds closure length validation against code.freevars. Builtins resolution improved with fallback to vm.builtins.dict() and module \dict unwrapping. |
Test coverage extra_tests/snippets/builtins_module.py |
New test function added with runtime assertion that test_func.__builtins__ is a dict instance. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~22 minutes
Possibly related PRs
- Pyfunction builtins and constructor #5823: Modifies PyFunction construction and builtins handling in the same core file with overlapping focus areas.
- SetFunctionAttribute #5968: Changes PyFunction constructor behavior, closure validation, and defaults/kwdefaults field handling in parallel updates.
Poem
🐰 Hoppy defaults find their way,
From OptionalArg to Option's ray,
Closure validation stands so tall,
Builtins unwrapped—dict for all!
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'correct builtins type under function' accurately summarizes the main changes: fixing builtins type handling in function initialization, including struct field changes from OptionalArg to Option types and builtins resolution logic. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
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.