Skip to content

Commit 1d2e33e

Browse files
committed
feat: magic len for RTuple types
1 parent a0665e1 commit 1d2e33e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mypyc/irbuild/ll_builder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,12 @@ def builtin_len(self, val: Value, line: int, use_pyssize_t: bool = False) -> Val
22602260
"""
22612261
typ = val.type
22622262
size_value = None
2263-
if is_list_rprimitive(typ) or is_tuple_rprimitive(typ) or is_bytes_rprimitive(typ):
2263+
if isinstance(typ, RTuple):
2264+
return Integer(
2265+
len(typ.types),
2266+
c_pyssize_t_rprimitive if use_pyssize_t else short_int_rprimitive,
2267+
)
2268+
elif is_list_rprimitive(typ) or is_tuple_rprimitive(typ) or is_bytes_rprimitive(typ):
22642269
size_value = self.primitive_op(var_object_size, [val], line)
22652270
elif is_set_rprimitive(typ) or is_frozenset_rprimitive(typ):
22662271
elem_address = self.add(GetElementPtr(val, PySetObject, "used"))

0 commit comments

Comments
 (0)