@@ -35,6 +35,7 @@ pub struct PyFunction {
35
35
defaults_and_kwdefaults : PyMutex < ( Option < PyTupleRef > , Option < PyDictRef > ) > ,
36
36
name : PyMutex < PyStrRef > ,
37
37
qualname : PyMutex < PyStrRef > ,
38
+ type_params : PyMutex < PyTupleRef > ,
38
39
#[ cfg( feature = "jit" ) ]
39
40
jitted_code : OnceCell < CompiledCode > ,
40
41
}
@@ -54,7 +55,8 @@ impl PyFunction {
54
55
closure : Option < PyTupleTyped < PyCellRef > > ,
55
56
defaults : Option < PyTupleRef > ,
56
57
kw_only_defaults : Option < PyDictRef > ,
57
- qualname : PyMutex < PyStrRef > ,
58
+ qualname : PyStrRef ,
59
+ type_params : PyTupleRef ,
58
60
) -> Self {
59
61
let name = PyMutex :: new ( code. obj_name . to_owned ( ) ) ;
60
62
PyFunction {
@@ -63,7 +65,8 @@ impl PyFunction {
63
65
closure,
64
66
defaults_and_kwdefaults : PyMutex :: new ( ( defaults, kw_only_defaults) ) ,
65
67
name,
66
- qualname,
68
+ qualname : PyMutex :: new ( qualname) ,
69
+ type_params : PyMutex :: new ( type_params) ,
67
70
#[ cfg( feature = "jit" ) ]
68
71
jitted_code : OnceCell :: new ( ) ,
69
72
}
@@ -428,6 +431,30 @@ impl PyFunction {
428
431
Ok ( ( ) )
429
432
}
430
433
434
+ #[ pygetset( magic) ]
435
+ fn type_params ( & self ) -> PyTupleRef {
436
+ self . type_params . lock ( ) . clone ( )
437
+ }
438
+
439
+ #[ pygetset( magic, setter) ]
440
+ fn set_type_params (
441
+ & self ,
442
+ value : PySetterValue < PyTupleRef > ,
443
+ vm : & VirtualMachine ,
444
+ ) -> PyResult < ( ) > {
445
+ match value {
446
+ PySetterValue :: Assign ( value) => {
447
+ * self . type_params . lock ( ) = value;
448
+ }
449
+ PySetterValue :: Delete => {
450
+ return Err (
451
+ vm. new_type_error ( "__type_params__ must be set to a tuple object" . to_string ( ) )
452
+ ) ;
453
+ }
454
+ }
455
+ Ok ( ( ) )
456
+ }
457
+
431
458
#[ cfg( feature = "jit" ) ]
432
459
#[ pymethod( magic) ]
433
460
fn jit ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < ( ) > {
0 commit comments