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

Method add_attr

mypyc/irbuild/classdef.py:332–345  ·  view source on GitHub ↗
(self, lvalue: NameExpr, stmt: AssignmentStmt)

Source from the content-addressed store, hash-verified

330 handle_ext_method(self.builder, self.cdef, fdef)
331
332 def add_attr(self, lvalue: NameExpr, stmt: AssignmentStmt) -> None:
333 # Variable declaration with no body
334 if isinstance(stmt.rvalue, TempNode):
335 return
336 # Only treat marked class variables as class variables.
337 if not (is_class_var(lvalue) or stmt.is_final_def):
338 return
339 typ = self.builder.load_native_type_object(self.cdef.fullname)
340 value = self.builder.accept(stmt.rvalue)
341 self.builder.primitive_op(
342 py_setattr_op, [typ, self.builder.load_str(lvalue.name), value], stmt.line
343 )
344 if self.builder.non_function_scope() and stmt.is_final_def:
345 self.builder.init_final_static(lvalue, value, self.cdef.name)
346
347 def finalize(self, ir: ClassIR) -> None:
348 # Call __init_subclass__ after class attributes have been set

Callers

nothing calls this directly

Calls 8

is_class_varFunction · 0.90
isinstanceFunction · 0.85
non_function_scopeMethod · 0.80
init_final_staticMethod · 0.80
acceptMethod · 0.45
primitive_opMethod · 0.45
load_strMethod · 0.45

Tested by

no test coverage detected