@@ -467,8 +467,7 @@ static int compiler_call_simple_kw_helper(struct compiler *c,
467
467
Py_ssize_t nkwelts );
468
468
static int compiler_call_helper (struct compiler * c , location loc ,
469
469
int n , asdl_expr_seq * args ,
470
- asdl_keyword_seq * keywords ,
471
- PyObject * extra_positional_arg );
470
+ asdl_keyword_seq * keywords );
472
471
static int compiler_try_except (struct compiler * , stmt_ty );
473
472
static int compiler_try_star_except (struct compiler * , stmt_ty );
474
473
static int compiler_set_qualname (struct compiler * );
@@ -2410,10 +2409,28 @@ compiler_class(struct compiler *c, stmt_ty s)
2410
2409
2411
2410
if (typeparams ) {
2412
2411
_Py_DECLARE_STR (type_params , ".type_params" );
2412
+ _Py_DECLARE_STR (generic_base , ".generic_base" );
2413
+ RETURN_IF_ERROR (compiler_nameop (c , loc , & _Py_STR (type_params ), Load ));
2414
+ ADDOP_I (c , loc , CALL_INTRINSIC_1 , INTRINSIC_SUBSCRIPT_GENERIC );
2415
+ RETURN_IF_ERROR (compiler_nameop (c , loc , & _Py_STR (generic_base ), Store ));
2416
+
2417
+ Py_ssize_t original_len = asdl_seq_LEN (s -> v .ClassDef .bases );
2418
+ asdl_expr_seq * bases = _Py_asdl_expr_seq_new (
2419
+ original_len + 1 , c -> c_arena );
2420
+ for (Py_ssize_t i = 0 ; i < original_len ; i ++ ) {
2421
+ asdl_seq_SET (bases , i , asdl_seq_GET (s -> v .ClassDef .bases , i ));
2422
+ }
2423
+ expr_ty name_node = _PyAST_Name (
2424
+ & _Py_STR (generic_base ), Load ,
2425
+ loc .lineno , loc .col_offset , loc .end_lineno , loc .end_col_offset , c -> c_arena
2426
+ );
2427
+ if (name_node == NULL ) {
2428
+ return ERROR ;
2429
+ }
2430
+ asdl_seq_SET (bases , original_len , name_node );
2413
2431
RETURN_IF_ERROR (compiler_call_helper (c , loc , 2 ,
2414
- s -> v .ClassDef .bases ,
2415
- s -> v .ClassDef .keywords ,
2416
- & _Py_STR (type_params )));
2432
+ bases ,
2433
+ s -> v .ClassDef .keywords ));
2417
2434
2418
2435
int is_in_class = c -> u -> u_ste -> ste_type_params_in_class ;
2419
2436
c -> u -> u_metadata .u_argcount = is_in_class ;
@@ -2434,8 +2451,7 @@ compiler_class(struct compiler *c, stmt_ty s)
2434
2451
} else {
2435
2452
RETURN_IF_ERROR (compiler_call_helper (c , loc , 2 ,
2436
2453
s -> v .ClassDef .bases ,
2437
- s -> v .ClassDef .keywords ,
2438
- NULL ));
2454
+ s -> v .ClassDef .keywords ));
2439
2455
}
2440
2456
2441
2457
/* 6. apply decorators */
@@ -4607,8 +4623,7 @@ compiler_call(struct compiler *c, expr_ty e)
4607
4623
loc = LOC (e );
4608
4624
return compiler_call_helper (c , loc , 0 ,
4609
4625
e -> v .Call .args ,
4610
- e -> v .Call .keywords ,
4611
- NULL );
4626
+ e -> v .Call .keywords );
4612
4627
}
4613
4628
4614
4629
static int
@@ -4758,18 +4773,16 @@ static int
4758
4773
compiler_call_helper (struct compiler * c , location loc ,
4759
4774
int n , /* Args already pushed */
4760
4775
asdl_expr_seq * args ,
4761
- asdl_keyword_seq * keywords ,
4762
- PyObject * extra_positional_arg )
4776
+ asdl_keyword_seq * keywords )
4763
4777
{
4764
- Py_ssize_t i , nseen , nelts , nkwelts , real_nelts ;
4778
+ Py_ssize_t i , nseen , nelts , nkwelts ;
4765
4779
4766
4780
RETURN_IF_ERROR (validate_keywords (c , keywords ));
4767
4781
4768
4782
nelts = asdl_seq_LEN (args );
4769
4783
nkwelts = asdl_seq_LEN (keywords );
4770
- real_nelts = extra_positional_arg == NULL ? nelts : nelts + 1 ;
4771
4784
4772
- if (real_nelts + nkwelts * 2 > STACK_USE_GUIDELINE ) {
4785
+ if (nelts + nkwelts * 2 > STACK_USE_GUIDELINE ) {
4773
4786
goto ex_call ;
4774
4787
}
4775
4788
for (i = 0 ; i < nelts ; i ++ ) {
@@ -4791,22 +4804,16 @@ compiler_call_helper(struct compiler *c, location loc,
4791
4804
assert (elt -> kind != Starred_kind );
4792
4805
VISIT (c , expr , elt );
4793
4806
}
4794
- if (extra_positional_arg != NULL ) {
4795
- RETURN_IF_ERROR (compiler_nameop (c , loc , extra_positional_arg , Load ));
4796
- ADDOP_I (c , loc , CALL_INTRINSIC_1 , INTRINSIC_SUBSCRIPT_GENERIC );
4797
- }
4798
4807
if (nkwelts ) {
4799
4808
VISIT_SEQ (c , keyword , keywords );
4800
4809
RETURN_IF_ERROR (
4801
4810
compiler_call_simple_kw_helper (c , loc , keywords , nkwelts ));
4802
4811
}
4803
- ADDOP_I (c , loc , CALL , n + real_nelts + nkwelts );
4812
+ ADDOP_I (c , loc , CALL , n + nelts + nkwelts );
4804
4813
return SUCCESS ;
4805
4814
4806
4815
ex_call :
4807
4816
4808
- assert (extra_positional_arg == NULL ); // TODO(PEP 695)
4809
-
4810
4817
/* Do positional arguments. */
4811
4818
if (n == 0 && nelts == 1 && ((expr_ty )asdl_seq_GET (args , 0 ))-> kind == Starred_kind ) {
4812
4819
VISIT (c , expr , ((expr_ty )asdl_seq_GET (args , 0 ))-> v .Starred .value );
0 commit comments