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

Class ClassIR

mypyc/ir/class_ir.py:82–497  ·  view source on GitHub ↗

Intermediate representation of a class. This also describes the runtime structure of native instances.

Source from the content-addressed store, hash-verified

80
81
82class ClassIR:
83 """Intermediate representation of a class.
84
85 This also describes the runtime structure of native instances.
86 """
87
88 def __init__(
89 self,
90 name: str,
91 module_name: str,
92 is_trait: bool = False,
93 is_generated: bool = False,
94 is_abstract: bool = False,
95 is_ext_class: bool = True,
96 is_final_class: bool = False,
97 ) -> None:
98 self.name = name
99 self.module_name = module_name
100 self.is_trait = is_trait
101 self.is_generated = is_generated
102 self.is_abstract = is_abstract
103 self.is_ext_class = is_ext_class
104 self.is_final_class = is_final_class
105 # An augmented class has additional methods separate from what mypyc generates.
106 # Right now the only one is dataclasses.
107 self.is_augmented = False
108 # Does this inherit from a Python class?
109 self.inherits_python = False
110 # Do instances of this class have __dict__?
111 self.has_dict = False
112 # Do we allow interpreted subclasses? Derived from a mypyc_attr.
113 self.allow_interpreted_subclasses = False
114 # Does this class need getseters to be generated for its attributes? (getseters are also
115 # added if is_generated is False)
116 self.needs_getseters = False
117 # Is this class declared as serializable (supports copy.copy
118 # and pickle) using @mypyc_attr(serializable=True)?
119 #
120 # Additionally, any class with this attribute False but with
121 # an __init__ that can be called without any arguments is
122 # *implicitly serializable*. In this case __init__ will be
123 # called during deserialization without arguments. If this is
124 # True, we match Python semantics and __init__ won't be called
125 # during deserialization.
126 #
127 # This impacts also all subclasses. Use is_serializable() to
128 # also consider base classes.
129 self._serializable = False
130 # If this a subclass of some built-in python class, the name
131 # of the object for that class. We currently only support this
132 # in a few ad-hoc cases.
133 self.builtin_base: str | None = None
134 # Default empty constructor
135 self.ctor = FuncDecl(name, None, module_name, FuncSignature([], RInstance(self)))
136 # Declare setup method that allocates and initializes an object. type is the
137 # type of the class being initialized, which could be another class if there
138 # is an interpreted subclass.
139 # TODO: Make it a regular method and generate its body in IR

Callers 11

setup_env_classFunction · 0.90
build_type_mapFunction · 0.90
setup_callable_classFunction · 0.90
deserialize_modulesFunction · 0.90
setUpMethod · 0.90
test_can_coerce_toMethod · 0.90
test_setter_nameMethod · 0.90
test_getter_nameMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by 6

setUpMethod · 0.72
test_can_coerce_toMethod · 0.72
test_setter_nameMethod · 0.72
test_getter_nameMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…