@@ -1255,71 +1255,6 @@ impl ExecutingFrame<'_> {
1255
1255
* extend_arg = true ;
1256
1256
Ok ( None )
1257
1257
}
1258
- bytecode:: Instruction :: TypeVar => {
1259
- let type_name = self . pop_value ( ) ;
1260
- let type_var: PyObjectRef =
1261
- typing:: TypeVar :: new ( vm, type_name. clone ( ) , vm. ctx . none ( ) , vm. ctx . none ( ) )
1262
- . into_ref ( & vm. ctx )
1263
- . into ( ) ;
1264
- self . push_value ( type_var) ;
1265
- Ok ( None )
1266
- }
1267
- bytecode:: Instruction :: TypeVarWithBound => {
1268
- let type_name = self . pop_value ( ) ;
1269
- let bound = self . pop_value ( ) ;
1270
- let type_var: PyObjectRef =
1271
- typing:: TypeVar :: new ( vm, type_name. clone ( ) , bound, vm. ctx . none ( ) )
1272
- . into_ref ( & vm. ctx )
1273
- . into ( ) ;
1274
- self . push_value ( type_var) ;
1275
- Ok ( None )
1276
- }
1277
- bytecode:: Instruction :: TypeVarWithConstraint => {
1278
- let type_name = self . pop_value ( ) ;
1279
- let constraint = self . pop_value ( ) ;
1280
- let type_var: PyObjectRef =
1281
- typing:: TypeVar :: new ( vm, type_name. clone ( ) , vm. ctx . none ( ) , constraint)
1282
- . into_ref ( & vm. ctx )
1283
- . into ( ) ;
1284
- self . push_value ( type_var) ;
1285
- Ok ( None )
1286
- }
1287
- bytecode:: Instruction :: TypeAlias => {
1288
- let name = self . pop_value ( ) ;
1289
- let type_params_obj = self . pop_value ( ) ;
1290
-
1291
- // CPython allows None or tuple for type_params
1292
- let type_params: PyTupleRef = if vm. is_none ( & type_params_obj) {
1293
- // If None, use empty tuple (matching CPython's behavior)
1294
- vm. ctx . empty_tuple . clone ( )
1295
- } else {
1296
- type_params_obj
1297
- . downcast ( )
1298
- . map_err ( |_| vm. new_type_error ( "Type params must be a tuple." ) ) ?
1299
- } ;
1300
-
1301
- let value = self . pop_value ( ) ;
1302
- let type_alias = typing:: TypeAliasType :: new ( name, type_params, value) ;
1303
- self . push_value ( type_alias. into_ref ( & vm. ctx ) . into ( ) ) ;
1304
- Ok ( None )
1305
- }
1306
- bytecode:: Instruction :: ParamSpec => {
1307
- let param_spec_name = self . pop_value ( ) ;
1308
- let param_spec: PyObjectRef = typing:: ParamSpec :: new ( param_spec_name. clone ( ) , vm)
1309
- . into_ref ( & vm. ctx )
1310
- . into ( ) ;
1311
- self . push_value ( param_spec) ;
1312
- Ok ( None )
1313
- }
1314
- bytecode:: Instruction :: TypeVarTuple => {
1315
- let type_var_tuple_name = self . pop_value ( ) ;
1316
- let type_var_tuple: PyObjectRef =
1317
- typing:: TypeVarTuple :: new ( type_var_tuple_name. clone ( ) , vm)
1318
- . into_ref ( & vm. ctx )
1319
- . into ( ) ;
1320
- self . push_value ( type_var_tuple) ;
1321
- Ok ( None )
1322
- }
1323
1258
bytecode:: Instruction :: MatchMapping => {
1324
1259
// Pop the subject from stack
1325
1260
let subject = self . pop_value ( ) ;
@@ -2272,6 +2207,53 @@ impl ExecutingFrame<'_> {
2272
2207
// Used for PEP 695: Generic[*type_params]
2273
2208
crate :: builtins:: genericalias:: subscript_generic ( arg, vm)
2274
2209
}
2210
+ bytecode:: IntrinsicFunction1 :: TypeVar => {
2211
+ let type_var: PyObjectRef =
2212
+ typing:: TypeVar :: new ( vm, arg. clone ( ) , vm. ctx . none ( ) , vm. ctx . none ( ) )
2213
+ . into_ref ( & vm. ctx )
2214
+ . into ( ) ;
2215
+ Ok ( type_var)
2216
+ }
2217
+ bytecode:: IntrinsicFunction1 :: ParamSpec => {
2218
+ let param_spec: PyObjectRef = typing:: ParamSpec :: new ( arg. clone ( ) , vm)
2219
+ . into_ref ( & vm. ctx )
2220
+ . into ( ) ;
2221
+ Ok ( param_spec)
2222
+ }
2223
+ bytecode:: IntrinsicFunction1 :: TypeVarTuple => {
2224
+ let type_var_tuple: PyObjectRef = typing:: TypeVarTuple :: new ( arg. clone ( ) , vm)
2225
+ . into_ref ( & vm. ctx )
2226
+ . into ( ) ;
2227
+ Ok ( type_var_tuple)
2228
+ }
2229
+ bytecode:: IntrinsicFunction1 :: TypeAlias => {
2230
+ // TypeAlias receives a tuple of (name, type_params, value)
2231
+ let tuple: PyTupleRef = arg
2232
+ . downcast ( )
2233
+ . map_err ( |_| vm. new_type_error ( "TypeAlias expects a tuple argument" ) ) ?;
2234
+
2235
+ if tuple. len ( ) != 3 {
2236
+ return Err ( vm. new_type_error ( format ! (
2237
+ "TypeAlias expects exactly 3 arguments, got {}" ,
2238
+ tuple. len( )
2239
+ ) ) ) ;
2240
+ }
2241
+
2242
+ let name = tuple. as_slice ( ) [ 0 ] . clone ( ) ;
2243
+ let type_params_obj = tuple. as_slice ( ) [ 1 ] . clone ( ) ;
2244
+ let value = tuple. as_slice ( ) [ 2 ] . clone ( ) ;
2245
+
2246
+ let type_params: PyTupleRef = if vm. is_none ( & type_params_obj) {
2247
+ vm. ctx . empty_tuple . clone ( )
2248
+ } else {
2249
+ type_params_obj
2250
+ . downcast ( )
2251
+ . map_err ( |_| vm. new_type_error ( "Type params must be a tuple." ) ) ?
2252
+ } ;
2253
+
2254
+ let type_alias = typing:: TypeAliasType :: new ( name, type_params, value) ;
2255
+ Ok ( type_alias. into_ref ( & vm. ctx ) . into ( ) )
2256
+ }
2275
2257
}
2276
2258
}
2277
2259
@@ -2292,6 +2274,20 @@ impl ExecutingFrame<'_> {
2292
2274
arg1. set_attr ( "__type_params__" , arg2, vm) ?;
2293
2275
Ok ( arg1)
2294
2276
}
2277
+ bytecode:: IntrinsicFunction2 :: TypeVarWithBound => {
2278
+ let type_var: PyObjectRef =
2279
+ typing:: TypeVar :: new ( vm, arg1. clone ( ) , arg2, vm. ctx . none ( ) )
2280
+ . into_ref ( & vm. ctx )
2281
+ . into ( ) ;
2282
+ Ok ( type_var)
2283
+ }
2284
+ bytecode:: IntrinsicFunction2 :: TypeVarWithConstraint => {
2285
+ let type_var: PyObjectRef =
2286
+ typing:: TypeVar :: new ( vm, arg1. clone ( ) , vm. ctx . none ( ) , arg2)
2287
+ . into_ref ( & vm. ctx )
2288
+ . into ( ) ;
2289
+ Ok ( type_var)
2290
+ }
2295
2291
}
2296
2292
}
2297
2293
0 commit comments