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

Class RPrimitive

mypyc/ir/rtypes.py:218–299  ·  view source on GitHub ↗

Primitive type such as 'object' or 'int'. These often have custom ops associated with them. The 'object' primitive type can be used to hold arbitrary Python objects. Different primitive types have different representations, and primitives may be unboxed or boxed. Primitive types do

Source from the content-addressed store, hash-verified

216
217@final
218class RPrimitive(RType):
219 """Primitive type such as 'object' or 'int'.
220
221 These often have custom ops associated with them. The 'object'
222 primitive type can be used to hold arbitrary Python objects.
223
224 Different primitive types have different representations, and
225 primitives may be unboxed or boxed. Primitive types don't need to
226 directly correspond to Python types, but most do.
227
228 NOTE: All supported primitive types are defined below
229 (e.g. object_rprimitive).
230 """
231
232 # Map from primitive names to primitive types and is used by deserialization
233 primitive_map: ClassVar[dict[str, RPrimitive]] = {}
234
235 def __init__(
236 self,
237 name: str,
238 *,
239 is_unboxed: bool,
240 is_refcounted: bool,
241 is_native_int: bool = False,
242 is_signed: bool = False,
243 ctype: str = "PyObject *",
244 size: int = PLATFORM_SIZE,
245 error_overlap: bool = False,
246 may_be_immortal: bool = True,
247 dependencies: tuple[Dependency, ...] | None = None,
248 ) -> None:
249 RPrimitive.primitive_map[name] = self
250
251 self.name = name
252 self.is_unboxed = is_unboxed
253 self.is_refcounted = is_refcounted
254 self.is_native_int = is_native_int
255 self.is_signed = is_signed
256 self._ctype = ctype
257 self.size = size
258 self.error_overlap = error_overlap
259 self._may_be_immortal = may_be_immortal and HAVE_IMMORTAL
260 self.dependencies = dependencies
261 if ctype == "CPyTagged":
262 self.c_undefined = "CPY_INT_TAG"
263 elif ctype in ("int16_t", "int32_t", "int64_t"):
264 # This is basically an arbitrary value that is pretty
265 # unlikely to overlap with a real value.
266 self.c_undefined = "-113"
267 elif ctype == "CPyPtr":
268 # TODO: Invent an overlapping error value?
269 self.c_undefined = "0"
270 elif ctype.endswith("*"):
271 # Boxed and pointer types use the null pointer as the error value.
272 self.c_undefined = "NULL"
273 elif ctype == "char":
274 self.c_undefined = "2"
275 elif ctype == "double":

Callers 1

rtypes.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…