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

Function translate_object_setattr

mypyc/irbuild/specialize.py:1280–1303  ·  view source on GitHub ↗
(builder: IRBuilder, expr: CallExpr, callee: RefExpr)

Source from the content-addressed store, hash-verified

1278
1279@specialize_function("__setattr__", object_rprimitive)
1280def translate_object_setattr(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
1281 is_super = isinstance(expr.callee, SuperExpr)
1282 is_object_callee = is_object(callee)
1283 if not ((is_super and len(expr.args) >= 2) or (is_object_callee and len(expr.args) >= 3)):
1284 return None
1285
1286 self_reg = builder.accept(expr.args[0]) if is_object_callee else builder.self()
1287 ir = builder.get_current_class_ir()
1288 if ir and (not ir.is_ext_class or ir.builtin_base or ir.inherits_python):
1289 return None
1290 # Need to offset by 1 for super().__setattr__ calls because there is no self arg in this case.
1291 name_idx = 0 if is_super else 1
1292 value_idx = 1 if is_super else 2
1293 attr_name = expr.args[name_idx]
1294 attr_value = expr.args[value_idx]
1295 value = builder.accept(attr_value)
1296
1297 if isinstance(attr_name, StrExpr) and ir and ir.has_attr(attr_name.value):
1298 name = attr_name.value
1299 value = builder.coerce(value, ir.attributes[name], expr.line)
1300 return builder.add(SetAttr(self_reg, name, value, expr.line))
1301
1302 name_reg = builder.accept(attr_name)
1303 return builder.call_c(generic_setattr, [self_reg, name_reg, value], expr.line)
1304
1305
1306@specialize_function("to_bytes", int_rprimitive)

Callers 1

Calls 11

SetAttrClass · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85
get_current_class_irMethod · 0.80
has_attrMethod · 0.80
is_objectFunction · 0.70
acceptMethod · 0.45
selfMethod · 0.45
coerceMethod · 0.45
addMethod · 0.45
call_cMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…