typevar as module#6834
Conversation
📝 WalkthroughWalkthroughA significant refactoring reorganizes typing-related types into a dedicated Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@crates/vm/src/stdlib/typevar.rs`:
- Around line 423-530: ParamSpec::__default__ currently evaluates
self.evaluate_default on every call but doesn't cache the result; modify the
method so that after calling the evaluate_default callable you store the result
into self.default_value (acquire the same lock as used for evaluate_default,
e.g., let mut default_value = self.default_value.lock(); *default_value =
evaluated_result.clone(); ) and then return that cached value; ensure the
initial NoDefault check still uses vm.ctx.typing_no_default and that you return
the cached default on subsequent calls instead of re-invoking evaluate_default.
- Around line 268-383: The TypeVar implementation (Constructor::py_new for
TypeVar) is not validating that the provided constraints are actual types nor
that the name is a string; likewise ParamSpec and TypeVarTuple constructors need
name validation and ParamSpec needs its bound validated with type_check. Fix: in
TypeVar::py_new ensure the extracted name is validated as a str (use vm.to_str
or equivalent/type_check for "name must be a str") and run type_check on each
constraint value (and on bound where present) before storing them; mirror this
logic in the ParamSpec constructor (validate name and call type_check on bound)
and in the TypeVarTuple constructor (validate name as str), referencing the
functions/constructors named py_new for TypeVar, ParamSpec, and TypeVarTuple and
the existing type_check helper to perform the validations and return TypeError
on invalid inputs.
Sorry, something went wrong.
8cbaf3c
into
RustPython:main
Jan 22, 2026
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.