You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhanced error messages for built-in functions—improved clarity when incorrect argument types are provided to function(), super(), and string interpolation operations.
✏️ Tip: You can customize this high-level summary in your review settings.
This PR introduces an error_msg attribute feature to the argument derive macro system, allowing custom error messages for argument validation. The derive implementation is enhanced to parse and handle error_msg in attribute declarations, and several builtins are updated to provide more specific error messages for their optional arguments.
Changes
Cohort / File(s)
Summary
Derive Macro Error Message Support crates/derive-impl/src/from_args.rs
Adds error_msg field to ArgAttribute struct and implements parsing logic to extract custom error messages from pyarg(error_msg = "...") annotations. Generates code to map conversion errors to type errors with the provided message, with guards against duplicate definitions.
Builtin Function Argument Validation crates/vm/src/builtins/function.rs
Annotates optional fields in PyFunctionNewArgs with error_msg attributes specifying type constraints for name, argdefs, closure, and kwdefaults arguments.
Refines conversion argument from OptionalArg<PyObjectRef> to Option<PyStrRef> with explicit error_msg attribute and simplified string validation logic. Moves validation to early checks instead of runtime pattern matching.
Builtin Super Type Argument crates/vm/src/builtins/super.rs
Narrows py_type argument in InitArgs from OptionalArg<PyObjectRef> to OptionalArg<PyTypeRef> and adds error_msg attribute. Removes runtime downcast logic in favor of compile-time argument type constraint.
fix fcntl, sslsocket traverse, super , excepthook #6623: Previously modified InitArgs::py_type in super.rs by widening it to OptionalArg<PyObjectRef>; this PR narrows it back to OptionalArg<PyTypeRef> with stricter validation.
Suggested reviewers
ShaharNaveh
arihant2math
Poem
🐰 A macro whispers soft and clear, "Show the user what they fear!" No more vague errors in the night, Just helpful messages, shining bright. ✨
Docstring coverage is 0.00% 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 'FromArgs with error_msg' accurately reflects the main change: adding an error_msg capability to the FromArgs derive macro and its argument parsing system.
✏️ 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by CodeRabbit
function(),super(), and string interpolation operations.✏️ Tip: You can customize this high-level summary in your review settings.