Skip to content

Commit 8d74068

Browse files
literals
1 parent cea5f47 commit 8d74068

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mypyc/irbuild/for_helpers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
TypeAlias,
2929
Var,
3030
)
31+
from mypy.types import LiteralType, TupleType, get_proper_type
3132
from mypyc.ir.ops import (
3233
ERR_NEVER,
3334
BasicBlock,
@@ -36,6 +37,7 @@
3637
IntOp,
3738
LoadAddress,
3839
LoadErrorValue,
40+
LoadLiteral,
3941
LoadMem,
4042
MethodCall,
4143
RaiseStandardError,
@@ -239,7 +241,17 @@ def sequence_from_generator_preallocate_helper(
239241
if isinstance(rtype, RTuple):
240242
# If input is RTuple, box it to tuple_rprimitive for generic iteration
241243
# TODO: this can be optimized a bit better with an unrolled ForRTuple helper
242-
items = [builder.add(TupleGet(sequence, i, line)) for i in range(len(rtype.types))]
244+
proper_type = get_proper_type(builder.types[sequence_expr])
245+
assert isinstance(proper_type, TupleType), proper_type
246+
247+
items = [
248+
builder.add(
249+
LoadLiteral(typ.value, object_rprimitive)
250+
if isinstance(typ, LiteralType) and isinstance(typ.value, (int, str, bool, float))
251+
else TupleGet(sequence, i, line)
252+
)
253+
for i, typ in enumerate(proper_type.items)
254+
]
243255
sequence = builder.new_tuple(items, line)
244256

245257
target_op = empty_op_llbuilder(length, line)

0 commit comments

Comments
 (0)