typing ParamSpec by youknowone · Pull Request #5837 · RustPython/RustPython
vm/src/stdlib/typing.rs (18)
19-20: Enhanced imports for new functionality
The addition of PyNumberMethods and AsNumber, Constructor, Representable traits properly supports the new operator overloading and construction capabilities being added.
63-63: Good enhancement with AsNumber trait
Adding the AsNumber trait to the TypeVar class enables the bitwise OR operator (|) for union types, which is a valuable Python 3.10+ feature.
177-187: Proper implementation of union operator
The AsNumber implementation correctly delegates to the _make_union function for handling the | operator, following Python's typing semantics.
305-305: Good module attribution
The call to set_module_from_caller ensures proper __module__ attribute setting, aligning with CPython behavior.
344-344: Enhanced ParamSpec with comprehensive functionality
The addition of AsNumber and Constructor traits significantly improves ParamSpec's usability and Python compatibility.
351-367: Well-implemented args and kwargs properties
The implementation properly creates ParamSpecArgs and ParamSpecKwargs instances with the correct origin reference, following the typing specification.
435-454: Comprehensive typing substitution methods
The addition of typing_subst and typing_prepare_subst methods properly implements ParamSpec's substitution semantics for generic type resolution.
457-467: Consistent AsNumber implementation
The ParamSpec AsNumber implementation matches TypeVar's pattern, ensuring uniform union operator behavior across typing constructs.
469-554: Robust ParamSpec constructor implementation
The constructor properly handles argument validation, variance checking, and default value management. The error messages are clear and the logic matches Python's typing behavior.
573-573: Enhanced NoDefault with Representable trait
Adding the Representable trait improves string representation consistency for the NoDefault singleton.
610-647: Well-structured TypeVarTuple enhancement
The addition of default value support, has_default method, and reduce method brings TypeVarTuple to feature parity with other typing constructs.
649-702: Comprehensive TypeVarTuple constructor
The constructor implementation follows the same pattern as TypeVar and ParamSpec, ensuring consistent behavior and proper error handling across typing classes.
704-710: Appropriate Representable implementation
The *{name} format correctly represents TypeVarTuple instances, matching Python's typing module behavior.
712-717: Updated helper function signature
The addition of the vm parameter to make_typevartuple enables proper default value initialization with the NoDefault singleton.
724-742: Well-designed ParamSpecArgs class
The implementation includes proper origin tracking and equality comparison, essential for ParamSpec functionality in the typing system.
754-763: Informative representation method
The repr implementation intelligently formats the output based on whether the origin has a __name__ attribute, providing meaningful debugging information.
769-808: Consistent ParamSpecKwargs implementation
ParamSpecKwargs mirrors ParamSpecArgs' design pattern, ensuring uniform behavior for both parameter specification components.
863-897: Excellent module attribution implementation
The caller() and set_module_from_caller() functions properly handle module attribution with appropriate special cases for builtins and generated modules. The documentation clearly explains the differences from CPython's implementation.