2
2
use crate :: { PyPayload , PyRef , VirtualMachine , class:: PyClassImpl , stdlib:: PyModule } ;
3
3
4
4
pub use crate :: stdlib:: typevar:: {
5
- ParamSpec , ParamSpecArgs , ParamSpecKwargs , TypeVar , TypeVarTuple ,
5
+ Generic , ParamSpec , ParamSpecArgs , ParamSpecKwargs , TypeVar , TypeVarTuple ,
6
6
} ;
7
7
pub use decl:: * ;
8
8
@@ -13,13 +13,15 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
13
13
TypeVarTuple :: make_class ( & vm. ctx ) ;
14
14
ParamSpecArgs :: make_class ( & vm. ctx ) ;
15
15
ParamSpecKwargs :: make_class ( & vm. ctx ) ;
16
+ Generic :: make_class ( & vm. ctx ) ;
16
17
extend_module ! ( vm, & module, {
17
18
"NoDefault" => vm. ctx. typing_no_default. clone( ) ,
18
19
"TypeVar" => TypeVar :: class( & vm. ctx) . to_owned( ) ,
19
20
"ParamSpec" => ParamSpec :: class( & vm. ctx) . to_owned( ) ,
20
21
"TypeVarTuple" => TypeVarTuple :: class( & vm. ctx) . to_owned( ) ,
21
22
"ParamSpecArgs" => ParamSpecArgs :: class( & vm. ctx) . to_owned( ) ,
22
23
"ParamSpecKwargs" => ParamSpecKwargs :: class( & vm. ctx) . to_owned( ) ,
24
+ "Generic" => Generic :: class( & vm. ctx) . to_owned( ) ,
23
25
} ) ;
24
26
module
25
27
}
@@ -116,55 +118,6 @@ pub(crate) mod decl {
116
118
}
117
119
}
118
120
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
-
168
121
// impl AsMapping for Generic {
169
122
// fn as_mapping() -> &'static PyMappingMethods {
170
123
// static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
0 commit comments