Skip to content

Commit 638d489

Browse files
[mypyc] feat: implement try_getting_literal in in rtuple helper [1/1]
1 parent c928847 commit 638d489

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mypyc/irbuild/expression.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from collections.abc import Sequence
1111
from typing import Callable
1212

13+
from mypy.checkexpr import try_getting_literal
1314
from mypy.nodes import (
1415
ARG_NAMED,
1516
ARG_POS,
@@ -50,7 +51,7 @@
5051
UnaryExpr,
5152
Var,
5253
)
53-
from mypy.types import Instance, ProperType, TupleType, TypeType, get_proper_type
54+
from mypy.types import Instance, LiteralType, ProperType, TupleType, TypeType, get_proper_type
5455
from mypyc.common import MAX_SHORT_INT
5556
from mypyc.ir.class_ir import ClassIR
5657
from mypyc.ir.func_ir import FUNC_CLASSMETHOD, FUNC_STATICMETHOD
@@ -786,7 +787,12 @@ def try_specialize_in_expr(
786787
left = builder.accept(lhs)
787788
tuple_val = builder.accept(rhs)
788789
assert isinstance(tuple_val.type, RTuple)
789-
items = [builder.add(TupleGet(tuple_val, i)) for i in range(len(tuple_val.type.types))]
790+
proper_type = get_proper_type(builder.types[rhs])
791+
assert isinstance(proper_type, TupleType)
792+
items = [
793+
LoadLiteral(typ.value, object_rprimitive) if isinstance(typ, LiteralType) else builder.add(TupleGet(tuple_val, i))
794+
for i, typ in enumerate(map(try_getting_literal, proper_type.items))
795+
]
790796

791797
if items is not None:
792798
assert left is not None

0 commit comments

Comments
 (0)