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

Class SetAttr

mypyc/ir/ops.py:912–958  ·  view source on GitHub ↗

obj.attr = src (for a native object)

Source from the content-addressed store, hash-verified

910
911@final
912class SetAttr(RegisterOp):
913 """obj.attr = src (for a native object)"""
914
915 error_kind = ERR_FALSE
916
917 def __init__(self, obj: Value, attr: str, src: Value, line: int) -> None:
918 super().__init__(line)
919 self.obj = obj
920 self.attr = attr
921 self.src = src
922 assert isinstance(obj.type, RInstance), "Attribute access not supported: %s" % obj.type
923 self.class_type = obj.type
924 self.type = bool_rprimitive
925 # If True, we can safely assume that the attribute is previously undefined
926 # and we don't use a setter
927 self.is_init = False
928
929 cl = self.class_type.class_ir
930 is_propset = False
931 for ir in cl.mro:
932 propset = ir.method_decls.get(PROPSET_PREFIX + attr)
933 if propset is not None:
934 is_propset = not propset.implicit
935 break
936 # If True, this op represents calling a property setter.
937 self.is_propset = is_propset
938
939 def mark_as_initializer(self) -> None:
940 self.is_init = True
941 self.error_kind = ERR_NEVER
942 self.type = void_rtype
943
944 def sources(self) -> list[Value]:
945 return [self.obj, self.src]
946
947 def set_sources(self, new: list[Value]) -> None:
948 self.obj, self.src = new
949
950 def stolen(self) -> list[Value]:
951 # The property setter method increfs the passed value so don't treat it as a steal
952 # to avoid leaking.
953 if self.is_propset:
954 return []
955 return [self.src]
956
957 def accept(self, visitor: OpVisitor[T]) -> T:
958 return visitor.visit_set_attr(self)
959
960
961# Default name space for statics, variables

Callers 15

translate_object_setattrFunction · 0.90
gen_property_setter_irFunction · 0.90
instantiate_env_classFunction · 0.90
assignMethod · 0.90
add_var_to_env_classMethod · 0.90
calculate_arg_defaultsFunction · 0.90
test_set_attrMethod · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…