File tree 5 files changed +72
-7
lines changed
5 files changed +72
-7
lines changed Original file line number Diff line number Diff line change @@ -1095,8 +1095,27 @@ impl Compiler {
1095
1095
self . store_name ( name. as_ref ( ) ) ?;
1096
1096
}
1097
1097
}
1098
- located_ast:: TypeParam :: ParamSpec ( _) => todo ! ( ) ,
1099
- located_ast:: TypeParam :: TypeVarTuple ( _) => todo ! ( ) ,
1098
+ located_ast:: TypeParam :: ParamSpec ( located_ast:: TypeParamParamSpec {
1099
+ name, ..
1100
+ } ) => {
1101
+ self . emit_load_const ( ConstantData :: Str {
1102
+ value : name. to_string ( ) ,
1103
+ } ) ;
1104
+ emit ! ( self , Instruction :: ParamSpec ) ;
1105
+ emit ! ( self , Instruction :: Duplicate ) ;
1106
+ self . store_name ( name. as_ref ( ) ) ?;
1107
+ }
1108
+ located_ast:: TypeParam :: TypeVarTuple ( located_ast:: TypeParamTypeVarTuple {
1109
+ name,
1110
+ ..
1111
+ } ) => {
1112
+ self . emit_load_const ( ConstantData :: Str {
1113
+ value : name. to_string ( ) ,
1114
+ } ) ;
1115
+ emit ! ( self , Instruction :: TypeVarTuple ) ;
1116
+ emit ! ( self , Instruction :: Duplicate ) ;
1117
+ self . store_name ( name. as_ref ( ) ) ?;
1118
+ }
1100
1119
} ;
1101
1120
}
1102
1121
emit ! (
Original file line number Diff line number Diff line change @@ -1257,8 +1257,18 @@ impl SymbolTableBuilder {
1257
1257
self . scan_expression ( binding, ExpressionContext :: Load ) ?;
1258
1258
}
1259
1259
}
1260
- ast:: located:: TypeParam :: ParamSpec ( _) => todo ! ( ) ,
1261
- ast:: located:: TypeParam :: TypeVarTuple ( _) => todo ! ( ) ,
1260
+ ast:: located:: TypeParam :: ParamSpec ( ast:: TypeParamParamSpec {
1261
+ name,
1262
+ range : param_spec_range,
1263
+ } ) => {
1264
+ self . register_name ( name, SymbolUsage :: Assigned , param_spec_range. start ) ?;
1265
+ }
1266
+ ast:: located:: TypeParam :: TypeVarTuple ( ast:: TypeParamTypeVarTuple {
1267
+ name,
1268
+ range : type_var_tuple_range,
1269
+ } ) => {
1270
+ self . register_name ( name, SymbolUsage :: Assigned , type_var_tuple_range. start ) ?;
1271
+ }
1262
1272
}
1263
1273
}
1264
1274
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -595,10 +595,12 @@ pub enum Instruction {
595
595
TypeVarWithBound ,
596
596
TypeVarWithConstraint ,
597
597
TypeAlias ,
598
+ TypeVarTuple ,
599
+ ParamSpec ,
598
600
// If you add a new instruction here, be sure to keep LAST_INSTRUCTION updated
599
601
}
600
602
// This must be kept up to date to avoid marshaling errors
601
- const LAST_INSTRUCTION : Instruction = Instruction :: TypeAlias ;
603
+ const LAST_INSTRUCTION : Instruction = Instruction :: ParamSpec ;
602
604
const _: ( ) = assert ! ( mem:: size_of:: <Instruction >( ) == 1 ) ;
603
605
604
606
impl From < Instruction > for u8 {
@@ -1291,6 +1293,8 @@ impl Instruction {
1291
1293
TypeVarWithBound => -1 ,
1292
1294
TypeVarWithConstraint => -1 ,
1293
1295
TypeAlias => -2 ,
1296
+ ParamSpec => 0 ,
1297
+ TypeVarTuple => 0 ,
1294
1298
}
1295
1299
}
1296
1300
@@ -1460,6 +1464,8 @@ impl Instruction {
1460
1464
TypeVarWithBound => w ! ( TypeVarWithBound ) ,
1461
1465
TypeVarWithConstraint => w ! ( TypeVarWithConstraint ) ,
1462
1466
TypeAlias => w ! ( TypeAlias ) ,
1467
+ ParamSpec => w ! ( ParamSpec ) ,
1468
+ TypeVarTuple => w ! ( TypeVarTuple ) ,
1463
1469
}
1464
1470
}
1465
1471
}
Original file line number Diff line number Diff line change @@ -1202,6 +1202,23 @@ impl ExecutingFrame<'_> {
1202
1202
self . push_value ( type_alias. into_ref ( & vm. ctx ) . into ( ) ) ;
1203
1203
Ok ( None )
1204
1204
}
1205
+ bytecode:: Instruction :: ParamSpec => {
1206
+ let param_spec_name = self . pop_value ( ) ;
1207
+ let param_spec: PyObjectRef = _typing:: make_paramspec ( param_spec_name. clone ( ) )
1208
+ . into_ref ( & vm. ctx )
1209
+ . into ( ) ;
1210
+ self . push_value ( param_spec) ;
1211
+ Ok ( None )
1212
+ }
1213
+ bytecode:: Instruction :: TypeVarTuple => {
1214
+ let type_var_tuple_name = self . pop_value ( ) ;
1215
+ let type_var_tuple: PyObjectRef =
1216
+ _typing:: make_typevartuple ( type_var_tuple_name. clone ( ) )
1217
+ . into_ref ( & vm. ctx )
1218
+ . into ( ) ;
1219
+ self . push_value ( type_var_tuple) ;
1220
+ Ok ( None )
1221
+ }
1205
1222
}
1206
1223
}
1207
1224
Original file line number Diff line number Diff line change @@ -75,18 +75,31 @@ pub(crate) mod _typing {
75
75
#[ pyclass( name = "ParamSpec" ) ]
76
76
#[ derive( Debug , PyPayload ) ]
77
77
#[ allow( dead_code) ]
78
- struct ParamSpec { }
78
+ pub ( crate ) struct ParamSpec {
79
+ name : PyObjectRef ,
80
+ }
81
+
79
82
#[ pyclass( flags( BASETYPE ) ) ]
80
83
impl ParamSpec { }
81
84
85
+ pub ( crate ) fn make_paramspec ( name : PyObjectRef ) -> ParamSpec {
86
+ ParamSpec { name }
87
+ }
88
+
82
89
#[ pyattr]
83
90
#[ pyclass( name = "TypeVarTuple" ) ]
84
91
#[ derive( Debug , PyPayload ) ]
85
92
#[ allow( dead_code) ]
86
- pub ( crate ) struct TypeVarTuple { }
93
+ pub ( crate ) struct TypeVarTuple {
94
+ name : PyObjectRef ,
95
+ }
87
96
#[ pyclass( flags( BASETYPE ) ) ]
88
97
impl TypeVarTuple { }
89
98
99
+ pub ( crate ) fn make_typevartuple ( name : PyObjectRef ) -> TypeVarTuple {
100
+ TypeVarTuple { name }
101
+ }
102
+
90
103
#[ pyattr]
91
104
#[ pyclass( name = "ParamSpecArgs" ) ]
92
105
#[ derive( Debug , PyPayload ) ]
You can’t perform that action at this time.
0 commit comments