Skip to content

Commit 1e8c7fe

Browse files
Update for_helpers.py
1 parent f6147d2 commit 1e8c7fe

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mypyc/irbuild/for_helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,15 @@ def get_expr_length(expr: Expression) -> int | None:
11921192
if isinstance(expr, (StrExpr, BytesExpr)):
11931193
return len(expr.value)
11941194
elif isinstance(expr, (ListExpr, TupleExpr)):
1195-
if all(get_expr_length(i) is not None for i in expr.items):
1196-
return len(expr.items)
1195+
# if there are no star expressions, or we know the length of them,
1196+
# we know the length of the expression
1197+
stars = [get_expr_length(i, context) for i in expr.items if isinstance(i, StarExpr)]
1198+
if None not in stars:
1199+
other = sum(not isinstance(i, StarExpr) for i in expr.items)
1200+
return other + sum(stars)
1201+
elif isinstance(expr, StarExpr):
1202+
# star expression needs some extra logic but that can come later, this is good for now
1203+
pass
11971204
# TODO: extend this, unrolling should come with a good performance boost
11981205
return None
11991206

0 commit comments

Comments
 (0)