MCPcopy Index your code
hub / github.com/python/mypy / TupleGet

Class TupleGet

mypyc/ir/ops.py:1082–1110  ·  view source on GitHub ↗

Get item of a fixed-length tuple (src[index]).

Source from the content-addressed store, hash-verified

1080
1081@final
1082class TupleGet(RegisterOp):
1083 """Get item of a fixed-length tuple (src[index])."""
1084
1085 error_kind = ERR_NEVER
1086
1087 def __init__(self, src: Value, index: int, line: int = -1, *, borrow: bool = False) -> None:
1088 super().__init__(line)
1089 assert isinstance(
1090 src.type, RTuple
1091 ), f"TupleGet only operates on tuples, not {type(src.type).__name__}"
1092 src_len = len(src.type.types)
1093 self.src = src
1094 self.index = index
1095 if index < 0:
1096 self.index += src_len
1097 assert (
1098 self.index <= src_len - 1
1099 ), f"Index out of range.\nsource type: {src.type}\nindex: {index}"
1100 self.type = src.type.types[index]
1101 self.is_borrowed = borrow
1102
1103 def sources(self) -> list[Value]:
1104 return [self.src]
1105
1106 def set_sources(self, new: list[Value]) -> None:
1107 (self.src,) = new
1108
1109 def accept(self, visitor: OpVisitor[T]) -> T:
1110 return visitor.visit_tuple_get(self)
1111
1112
1113@final

Callers 15

gen_conditionMethod · 0.90
begin_bodyMethod · 0.90
begin_bodyMethod · 0.90
begin_bodyMethod · 0.90
vec_popFunction · 0.90
assignMethod · 0.90
get_sys_exc_infoFunction · 0.90
transform_index_exprFunction · 0.90
try_specialize_in_exprFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_tuple_getMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…