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

Class GetAttr

mypyc/ir/ops.py:873–908  ·  view source on GitHub ↗

obj.attr (for a native object)

Source from the content-addressed store, hash-verified

871
872@final
873class GetAttr(RegisterOp):
874 """obj.attr (for a native object)"""
875
876 error_kind = ERR_MAGIC
877
878 def __init__(
879 self,
880 obj: Value,
881 attr: str,
882 line: int,
883 *,
884 borrow: bool = False,
885 allow_error_value: bool = False,
886 ) -> None:
887 super().__init__(line)
888 self.obj = obj
889 self.attr = attr
890 self.allow_error_value = allow_error_value
891 assert isinstance(obj.type, RInstance), "Attribute access not supported: %s" % obj.type
892 self.class_type = obj.type
893 attr_type = obj.type.attr_type(attr)
894 self.type = attr_type
895 if allow_error_value:
896 self.error_kind = ERR_NEVER
897 elif attr_type.error_overlap:
898 self.error_kind = ERR_MAGIC_OVERLAPPING
899 self.is_borrowed = borrow and attr_type.is_refcounted
900
901 def sources(self) -> list[Value]:
902 return [self.obj]
903
904 def set_sources(self, new: list[Value]) -> None:
905 (self.obj,) = new
906
907 def accept(self, visitor: OpVisitor[T]) -> T:
908 return visitor.visit_get_attr(self)
909
910
911@final

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by 5

test_get_attrMethod · 0.72
test_get_attr_mergedMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…