22use crate :: { PyPayload , PyRef , VirtualMachine , class:: PyClassImpl , stdlib:: PyModule } ;
33
44pub use crate :: stdlib:: typevar:: {
5- ParamSpec , ParamSpecArgs , ParamSpecKwargs , TypeVar , TypeVarTuple ,
5+ Generic , ParamSpec , ParamSpecArgs , ParamSpecKwargs , TypeVar , TypeVarTuple ,
66} ;
77pub use decl:: * ;
88
@@ -13,13 +13,15 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
1313 TypeVarTuple :: make_class ( & vm. ctx ) ;
1414 ParamSpecArgs :: make_class ( & vm. ctx ) ;
1515 ParamSpecKwargs :: make_class ( & vm. ctx ) ;
16+ Generic :: make_class ( & vm. ctx ) ;
1617 extend_module ! ( vm, & module, {
1718 "NoDefault" => vm. ctx. typing_no_default. clone( ) ,
1819 "TypeVar" => TypeVar :: class( & vm. ctx) . to_owned( ) ,
1920 "ParamSpec" => ParamSpec :: class( & vm. ctx) . to_owned( ) ,
2021 "TypeVarTuple" => TypeVarTuple :: class( & vm. ctx) . to_owned( ) ,
2122 "ParamSpecArgs" => ParamSpecArgs :: class( & vm. ctx) . to_owned( ) ,
2223 "ParamSpecKwargs" => ParamSpecKwargs :: class( & vm. ctx) . to_owned( ) ,
24+ "Generic" => Generic :: class( & vm. ctx) . to_owned( ) ,
2325 } ) ;
2426 module
2527}
@@ -116,55 +118,6 @@ pub(crate) mod decl {
116118 }
117119 }
118120
119- /// Helper function to call typing module functions with cls as first argument
120- /// Similar to CPython's call_typing_args_kwargs
121- fn call_typing_args_kwargs (
122- name : & ' static str ,
123- cls : PyTypeRef ,
124- args : FuncArgs ,
125- vm : & VirtualMachine ,
126- ) -> PyResult {
127- let typing = vm. import ( "typing" , 0 ) ?;
128- let func = typing. get_attr ( name, vm) ?;
129-
130- // Prepare arguments: (cls, *args)
131- let mut call_args = vec ! [ cls. into( ) ] ;
132- call_args. extend ( args. args ) ;
133-
134- // Call with prepared args and original kwargs
135- let func_args = FuncArgs {
136- args : call_args,
137- kwargs : args. kwargs ,
138- } ;
139-
140- func. call ( func_args, vm)
141- }
142-
143- #[ pyattr]
144- #[ pyclass( name = "Generic" , module = "typing" ) ]
145- #[ derive( Debug , PyPayload ) ]
146- #[ allow( dead_code) ]
147- pub ( crate ) struct Generic { }
148-
149- // #[pyclass(with(AsMapping), flags(BASETYPE))]
150- #[ pyclass( flags( BASETYPE ) ) ]
151- impl Generic {
152- #[ pyclassmethod]
153- fn __class_getitem__ ( cls : PyTypeRef , args : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
154- // Convert single arg to FuncArgs
155- let func_args = FuncArgs {
156- args : vec ! [ args] ,
157- kwargs : Default :: default ( ) ,
158- } ;
159- call_typing_args_kwargs ( "_generic_class_getitem" , cls, func_args, vm)
160- }
161-
162- #[ pyclassmethod]
163- fn __init_subclass__ ( cls : PyTypeRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
164- call_typing_args_kwargs ( "_generic_init_subclass" , cls, args, vm)
165- }
166- }
167-
168121 // impl AsMapping for Generic {
169122 // fn as_mapping() -> &'static PyMappingMethods {
170123 // static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
0 commit comments