Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 19, 2026

Summary by CodeRabbit

  • New Features
    • 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

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.
Builtin Interpolation Argument Handling
crates/vm/src/builtins/interpolation.rs
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.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

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.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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.

❤️ Share

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

@youknowone youknowone marked this pull request as ready for review January 19, 2026 17:04
@youknowone youknowone merged commit 2da102f into RustPython:main Jan 19, 2026
13 checks passed
@youknowone youknowone deleted the FromArgs branch January 19, 2026 17:10
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