in Lib/compiler/static/types.py [0:0]
def __init__(self) -> None:
self._generic_types: GenericTypesDict = {}
self._literal_types: Dict[Tuple[Value, object], Value] = {}
self._nonliteral_types: Dict[Value, Value] = {}
self._exact_types: Dict[Class, Class] = {}
self._inexact_types: Dict[Class, Class] = {}
# Bringing up the type system is a little special as we have dependencies
# amongst type and object
self.type: Class = Class.__new__(Class)
self.type.type_name = TypeName("builtins", "type")
self.type.type_env = self
self.type.klass = self.type
self.type.instance = self.type
self.type.members = {}
self.type.is_exact = False
self.type.is_final = False
self.type.allow_weakrefs = False
self.type.donotcompile = False
self.type._mro = None
self.type.pytype = type
self.type._member_nodes = {}
self.type.dynamic_builtinmethod_dispatch = False
self.object: Class = BuiltinObject(
TypeName("builtins", "object"),
self,
bases=[],
)
self.type.bases = [self.object]
self.dynamic = DynamicClass(self)
self.builtin_method_desc = Class(
TypeName("types", "MethodDescriptorType"),
self,
is_exact=True,
)
self.builtin_method = Class(
TypeName("types", "BuiltinMethodType"), self, is_exact=True
)
# We special case make_type_dict() on object for bootstrapping purposes.
self.object.pytype = object
self.object.make_type_dict()
self.type.make_type_dict()
self.str = StrClass(self)
self.int = NumClass(TypeName("builtins", "int"), self, pytype=int)
self.float = NumClass(TypeName("builtins", "float"), self, pytype=float)
self.complex = NumClass(TypeName("builtins", "complex"), self, pytype=complex)
self.bytes = Class(
TypeName("builtins", "bytes"), self, [self.object], pytype=bytes
)
self.bool: Class = BoolClass(self)
self.cbool: CIntType = CIntType(TYPED_BOOL, self, name_override="cbool")
self.int64enum: CEnumType = CEnumType(self)
self.int8: CIntType = CIntType(TYPED_INT8, self)
self.int16: CIntType = CIntType(TYPED_INT16, self)
self.int32: CIntType = CIntType(TYPED_INT32, self)
self.int64: CIntType = CIntType(TYPED_INT64, self)
self.uint8: CIntType = CIntType(TYPED_UINT8, self)
self.uint16: CIntType = CIntType(TYPED_UINT16, self)
self.uint32: CIntType = CIntType(TYPED_UINT32, self)
self.uint64: CIntType = CIntType(TYPED_UINT64, self)
# TODO uses of these to check if something is a CInt wrongly exclude literals
self.signed_cint_types: Sequence[CIntType] = [
self.int8,
self.int16,
self.int32,
self.int64,
]
self.unsigned_cint_types: Sequence[CIntType] = [
self.uint8,
self.uint16,
self.uint32,
self.uint64,
]
self.all_cint_types: Sequence[CIntType] = (
self.signed_cint_types + self.unsigned_cint_types
)
self.none = NoneType(self)
self.optional = OptionalType(self)
self.name_to_type: Mapping[str, Class] = {
"NoneType": self.none,
"object": self.object,
"str": self.str,
"__static__.int8": self.int8,
"__static__.int16": self.int16,
"__static__.int32": self.int32,
"__static__.int64": self.int64,
"__static__.uint8": self.uint8,
"__static__.uint16": self.uint16,
"__static__.uint32": self.uint32,
"__static__.uint64": self.uint64,
}
if spamobj is not None:
self.spam_obj: Optional[GenericClass] = GenericClass(
GenericTypeName(
"xxclassloader", "spamobj", (GenericParameter("T", 0, self),)
),
self,
[self.object],
pytype=spamobj,
)
else:
self.spam_obj = None
checked_dict_type_name = GenericTypeName(
"__static__",
"chkdict",
(GenericParameter("K", 0, self), GenericParameter("V", 1, self)),
)
checked_list_type_name = GenericTypeName(
"__static__", "chklist", (GenericParameter("T", 0, self),)
)
self.checked_dict = CheckedDict(
checked_dict_type_name,
self,
[self.object],
pytype=chkdict,
is_exact=True,
)
self.checked_list = CheckedList(
checked_list_type_name,
self,
[self.object],
pytype=chklist,
is_exact=True,
)
self.ellipsis = Class(
TypeName("builtins", "ellipsis"),
self,
[self.object],
pytype=type(...),
is_exact=True,
)
self.array = ArrayClass(
GenericTypeName("__static__", "Array", (GenericParameter("T", 0, self),)),
self,
is_exact=True,
)
self.dict = DictClass(self, is_exact=False)
self.list = ListClass(self)
self.set = SetClass(self, is_exact=False)
self.tuple = TupleClass(self)
self.function = Class(TypeName("types", "FunctionType"), self, is_exact=True)
self.method = Class(TypeName("types", "MethodType"), self, is_exact=True)
self.member = Class(
TypeName("types", "MemberDescriptorType"), self, is_exact=True
)
self.slice = Class(TypeName("builtins", "slice"), self, is_exact=True)
self.char = CIntType(TYPED_INT8, self, name_override="char")
self.module = ModuleType(self)
self.double = CDoubleType(self)
# Vectors are just currently a special type of array that support
# methods that resize them.
self.vector_type_param = GenericParameter("T", 0, self)
self.vector_type_name = GenericTypeName(
"__static__", "Vector", (self.vector_type_param,)
)
self.vector = VectorClass(self.vector_type_name, self, is_exact=True)
self.allowed_array_types: List[Class] = [
self.int8,
self.int16,
self.int32,
self.int64,
self.uint8,
self.uint16,
self.uint32,
self.uint64,
self.char,
self.double,
self.float,
]
self.static_method = StaticMethodDecorator(
TypeName("builtins", "staticmethod"),
self,
pytype=staticmethod,
)
self.class_method = ClassMethodDecorator(
TypeName("builtins", "classmethod"),
self,
pytype=classmethod,
)
self.final_method = TypingFinalDecorator(TypeName("typing", "final"), self)
self.awaitable = AwaitableType(self)
self.union = UnionType(self)
self.final = FinalClass(
GenericTypeName("typing", "Final", (GenericParameter("T", 0, self),)), self
)
self.classvar = ClassVar(
GenericTypeName("typing", "ClassVar", (GenericParameter("T", 0, self),)),
self,
)
self.readonly_type = ReadonlyType(
GenericTypeName("builtins", "Readonly", (GenericParameter("T", 0, self),)),
self,
)
self.exact = ExactClass(
GenericTypeName("typing", "Exact", (GenericParameter("T", 0, self),)), self
)
self.named_tuple = Class(TypeName("typing", "NamedTuple"), self)
self.protocol = Class(TypeName("typing", "Protocol"), self)
self.literal = LiteralType(TypeName("typing", "Literal"), self)
self.annotated = AnnotatedType(TypeName("typing", "Annotated"), self)
self.base_exception = Class(
TypeName("builtins", "BaseException"), self, pytype=BaseException
)
self.exception = Class(
TypeName("builtins", "Exception"),
self,
bases=[self.base_exception],
pytype=Exception,
)
self.allow_weakrefs = AllowWeakrefsDecorator(
TypeName("__static__", "allow_weakrefs"), self
)
self.dynamic_return = DynamicReturnDecorator(
TypeName("__static__", "dynamic_return"), self
)
self.inline = InlineFunctionDecorator(TypeName("__static__", "inline"), self)
self.donotcompile = DoNotCompileDecorator(
TypeName("__static__", "_donotcompile"), self
)
self.property = PropertyDecorator(
TypeName("builtins", "property"),
self,
pytype=property,
)
self.cached_property = CachedPropertyDecorator(
TypeName("cinder", "cached_property"), self
)
self.async_cached_property = AsyncCachedPropertyDecorator(
TypeName("cinder", "async_cached_property"), self
)
self.constant_types: Mapping[Type[object], Value] = {
str: self.str.exact_type().instance,
int: self.int.exact_type().instance,
float: self.float.exact_type().instance,
complex: self.complex.exact_type().instance,
bytes: self.bytes.instance,
bool: self.bool.instance,
type(None): self.none.instance,
tuple: self.tuple.exact_type().instance,
type(...): self.ellipsis.instance,
frozenset: self.set.instance,
}
self.enum: EnumType = EnumType(self)
self.int_enum: IntEnumType = IntEnumType(self)
self.string_enum: StringEnumType = StringEnumType(self)
self.exc_context_decorator = ContextDecoratorClass(
self, TypeName("__static__", "ExcContextDecorator")
)
self.context_decorator = ContextDecoratorClass(
self,
TypeName("__static__", "ContextDecorator"),
bases=[self.exc_context_decorator],
)
if spamobj is not None:
T = GenericParameter("T", 0, self)
U = GenericParameter("U", 1, self)
XXGENERIC_TYPE_NAME = GenericTypeName("xxclassloader", "XXGeneric", (T, U))
self.xx_generic: XXGeneric = XXGeneric(
XXGENERIC_TYPE_NAME, self, [self.object]
)