Skip to content

Commit 7726c2d

Browse files
[mypyc] feat: implement try_getting_literal in preallocate helper
During the rtuple boxing stage, if any of the values are a known Literal type we can skip the struct access and just load the static literal
1 parent 4171da0 commit 7726c2d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mypyc/irbuild/for_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from typing import Callable, ClassVar
1111

12+
from mypy.checkexpr import try_getting_literal
1213
from mypy.nodes import (
1314
ARG_POS,
1415
BytesExpr,
@@ -255,7 +256,7 @@ def sequence_from_generator_preallocate_helper(
255256
if isinstance(typ, LiteralType)
256257
else TupleGet(sequence, i, line)
257258
)
258-
for i, typ in enumerate(get_proper_types(proper_type.items))
259+
for i, typ in enumerate(map(try_getting_literal, proper_type.items))
259260
]
260261
items = list(map(builder.add, get_item_ops))
261262
sequence = builder.new_tuple(items, line)

0 commit comments

Comments
 (0)