@@ -3414,21 +3414,23 @@ codegen_boolop(compiler *c, expr_ty e)
34143414
34153415static int
34163416starunpack_helper_impl (compiler * c , location loc ,
3417- asdl_expr_seq * elts , PyObject * injected_arg , int pushed ,
3417+ asdl_expr_seq * elts , Py_ssize_t start ,
3418+ PyObject * injected_arg , int pushed ,
34183419 int build , int add , int extend , int tuple )
34193420{
3420- Py_ssize_t n = asdl_seq_LEN (elts );
3421+ Py_ssize_t end = asdl_seq_LEN (elts );
3422+ Py_ssize_t n = end - start ;
34213423 int big = n + pushed + (injected_arg ? 1 : 0 ) > _PY_STACK_USE_GUIDELINE ;
34223424 int seen_star = 0 ;
3423- for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
3425+ for (Py_ssize_t i = start ; i < end ; i ++ ) {
34243426 expr_ty elt = asdl_seq_GET (elts , i );
34253427 if (elt -> kind == Starred_kind ) {
34263428 seen_star = 1 ;
34273429 break ;
34283430 }
34293431 }
34303432 if (!seen_star && !big ) {
3431- for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
3433+ for (Py_ssize_t i = start ; i < end ; i ++ ) {
34323434 expr_ty elt = asdl_seq_GET (elts , i );
34333435 VISIT (c , expr , elt );
34343436 }
@@ -3448,7 +3450,7 @@ starunpack_helper_impl(compiler *c, location loc,
34483450 ADDOP_I (c , loc , build , pushed );
34493451 sequence_built = 1 ;
34503452 }
3451- for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
3453+ for (Py_ssize_t i = start ; i < end ; i ++ ) {
34523454 expr_ty elt = asdl_seq_GET (elts , i );
34533455 if (elt -> kind == Starred_kind ) {
34543456 if (sequence_built == 0 ) {
@@ -3476,12 +3478,25 @@ starunpack_helper_impl(compiler *c, location loc,
34763478 return SUCCESS ;
34773479}
34783480
3481+ static bool
3482+ is_empty_starred_tuple (expr_ty elt )
3483+ {
3484+ if (elt -> kind != Starred_kind ) {
3485+ return false;
3486+ }
3487+ expr_ty value = elt -> v .Starred .value ;
3488+ return value -> kind == Tuple_kind &&
3489+ value -> v .Tuple .ctx == Load &&
3490+ asdl_seq_LEN (value -> v .Tuple .elts ) == 0 ;
3491+ }
3492+
34793493static int
34803494starunpack_helper (compiler * c , location loc ,
34813495 asdl_expr_seq * elts , int pushed ,
34823496 int build , int add , int extend , int tuple )
34833497{
3484- return starunpack_helper_impl (c , loc , elts , NULL , pushed ,
3498+ Py_ssize_t start = asdl_seq_LEN (elts ) && is_empty_starred_tuple (asdl_seq_GET (elts , 0 ));
3499+ return starunpack_helper_impl (c , loc , elts , start , NULL , pushed ,
34853500 build , add , extend , tuple );
34863501}
34873502
@@ -4446,7 +4461,7 @@ codegen_call_helper_impl(compiler *c, location loc,
44464461 VISIT (c , expr , ((expr_ty )asdl_seq_GET (args , 0 ))-> v .Starred .value );
44474462 }
44484463 else {
4449- RETURN_IF_ERROR (starunpack_helper_impl (c , loc , args , injected_arg , n ,
4464+ RETURN_IF_ERROR (starunpack_helper_impl (c , loc , args , 0 , injected_arg , n ,
44504465 BUILD_LIST , LIST_APPEND , LIST_EXTEND , 1 ));
44514466 }
44524467 /* Then keyword arguments */
0 commit comments