|
29 | 29 | UnaryExpr, |
30 | 30 | Var, |
31 | 31 | ) |
32 | | -from mypy.types import LiteralType, TupleType |
| 32 | +from mypy.types import LiteralType, TupleType, get_proper_type |
33 | 33 | from mypyc.irbuild.builder import IRBuilder |
34 | 34 | from mypyc.irbuild.util import bytes_from_str |
35 | 35 |
|
@@ -91,12 +91,13 @@ def constant_fold_expr(builder: IRBuilder, expr: Expression) -> ConstantValue | |
91 | 91 | isinstance(item, str) for item in folded_items |
92 | 92 | ): |
93 | 93 | return folded_callee.join(folded_items) # type: ignore [arg-type] |
94 | | - expr_type = builder.types[arg] |
95 | | - if isinstance(expr_type, TupleType) and all( |
96 | | - isinstance(i, LiteralType) and isinstance(i.value, str) |
97 | | - for i in expr_type.items |
98 | | - ): |
99 | | - return folded_callee.join(i.value for i in expr_type.items) # type: ignore [attr-defined] |
| 94 | + if expr_type := builder.types.get(arg): |
| 95 | + proper_type = get_proper_type(expr_type) |
| 96 | + if isinstance(proper_type, TupleType) and all( |
| 97 | + isinstance(i, LiteralType) and isinstance(i.value, str) |
| 98 | + for i in proper_type.items |
| 99 | + ): |
| 100 | + return folded_callee.join(i.value for i in proper_type.items) # type: ignore [attr-defined] |
100 | 101 |
|
101 | 102 | # builtins.bytes methods |
102 | 103 | elif isinstance(folded_callee, bytes): |
|
0 commit comments