MCPcopy Create free account
hub / github.com/python/mypy / Box

Class Box

mypyc/ir/ops.py:1154–1181  ·  view source on GitHub ↗

box(type, src) This converts from a potentially unboxed representation to a straight Python object. Only supported for types with an unboxed representation.

Source from the content-addressed store, hash-verified

1152
1153@final
1154class Box(RegisterOp):
1155 """box(type, src)
1156
1157 This converts from a potentially unboxed representation to a straight Python object.
1158 Only supported for types with an unboxed representation.
1159 """
1160
1161 error_kind = ERR_NEVER
1162
1163 def __init__(self, src: Value, line: int = -1) -> None:
1164 super().__init__(line)
1165 self.src = src
1166 self.type = object_rprimitive
1167 # When we box None and bool values, we produce a borrowed result
1168 if is_none_rprimitive(self.src.type) or is_bool_or_bit_rprimitive(self.src.type):
1169 self.is_borrowed = True
1170
1171 def sources(self) -> list[Value]:
1172 return [self.src]
1173
1174 def set_sources(self, new: list[Value]) -> None:
1175 (self.src,) = new
1176
1177 def stolen(self) -> list[Value]:
1178 return [self.src]
1179
1180 def accept(self, visitor: OpVisitor[T]) -> T:
1181 return visitor.visit_box(self)
1182
1183
1184@final

Callers 6

boxMethod · 0.90
test_box_intMethod · 0.90
test_box_i64Method · 0.90
test_box_vecMethod · 0.90
test_inc_ref_noneMethod · 0.90
test_inc_ref_boolMethod · 0.90

Calls

no outgoing calls

Tested by 5

test_box_intMethod · 0.72
test_box_i64Method · 0.72
test_box_vecMethod · 0.72
test_inc_ref_noneMethod · 0.72
test_inc_ref_boolMethod · 0.72