Skip to content

Commit fe5003c

Browse files
Update constant_fold.py
1 parent f680098 commit fe5003c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

mypyc/irbuild/constant_fold.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from typing import Final, Union, overload
1414

15+
from mypy.checkexpr import try_getting_literal
1516
from mypy.constant_fold import constant_fold_binary_op, constant_fold_unary_op
1617
from mypy.nodes import (
1718
BytesExpr,
@@ -94,11 +95,12 @@ def constant_fold_expr(builder: IRBuilder, expr: Expression) -> ConstantValue |
9495
if expr_type := builder.types.get(arg):
9596
proper_type = get_proper_type(expr_type)
9697
if isinstance(proper_type, TupleType):
97-
types = list(map(get_proper_type, proper_type.items))
98-
if all(
99-
isinstance(i, LiteralType) and isinstance(i.value, str) for i in types
100-
):
101-
return folded_callee.join(i.value for i in types) # type: ignore [attr-defined]
98+
values: list[str] = []
99+
for item_type in map(try_getting_literal, proper_type.items):
100+
if not (isinstance(item_type, LiteralType) and isinstance(item_type.value, str)):
101+
return None
102+
values.append(item_type.value)
103+
return folded_callee.join(values)
102104

103105
# builtins.bytes methods
104106
elif isinstance(folded_callee, bytes):

0 commit comments

Comments
 (0)