class documentation

class TypeType(ProperType): (source)

View In Hierarchy

For types like Type[User].

This annotates variables that are class objects, constrained by the type argument. See PEP 484 for more details.

We may encounter expressions whose values are specific classes; those are represented as callables (possibly overloaded) corresponding to the class's constructor's signature and returning an instance of that class. The difference with Type[C] is that those callables always represent the exact class given as the return type; Type[C] represents any class that's a subclass of C, and C may also be a type variable or a union (or Any).

Many questions around subtype relationships between Type[C1] and def(...) -> C2 are answered by looking at the subtype relationships between C1 and C2, since Type[] is considered covariant.

There's an unsolved problem with constructor signatures (also unsolved in PEP 484): calling a variable whose type is Type[C] assumes the constructor signature for C, even though a subclass of C might completely change the constructor signature. For now we just assume that users of Type[C] are careful not to do that (in the future we might detect when they are violating that assumption).

Class Method deserialize Undocumented
Static Method make​_normalized Undocumented
Method __eq__ Undocumented
Method __hash__ Undocumented
Method __init__ To ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]], item of type UnionType must be handled through make_normalized static method.
Method accept Undocumented
Method serialize Undocumented
Class Variable __slots__ Undocumented
Instance Variable item Undocumented

Inherited from Type (via ProperType):

Method __repr__ Undocumented
Method can​_be​_false​_default Undocumented
Method can​_be​_true​_default Undocumented
Instance Variable can​_be​_false Undocumented
Instance Variable can​_be​_true Undocumented

Inherited from Context (via ProperType, Type):

Method get​_column Don't use. Use x.column.
Method get​_line Don't use. Use x.line.
Method set​_line If target is a node, pull line (and column) information into this node. If column is specified, this will override any column information coming from a node.
Instance Variable column Undocumented
Instance Variable end​_line Undocumented
Instance Variable line Undocumented
@classmethod
def deserialize(cls, data): (source)

Undocumented

Parameters
data:JsonDictUndocumented
Returns
TypeUndocumented
@staticmethod
def make_normalized(item, *, line=-1, column=-1): (source)

Undocumented

Parameters
item:TypeUndocumented
line:intUndocumented
column:intUndocumented
Returns
ProperTypeUndocumented
def __eq__(self, other): (source)

Undocumented

Parameters
other:objectUndocumented
Returns
boolUndocumented
def __hash__(self): (source)

Undocumented

Returns
intUndocumented
def __init__(self, item, *, line=-1, column=-1): (source)
To ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]], item of type UnionType must be handled through make_normalized static method.
Parameters
item:Bogus[Union[Instance, AnyType, TypeVarType, TupleType, NoneType, CallableType]]Undocumented
line:intUndocumented
column:intUndocumented
def accept(self, visitor): (source)

Undocumented

Parameters
visitor:TypeVisitor[T]Undocumented
Returns
TUndocumented
def serialize(self): (source)

Undocumented

Returns
JsonDictUndocumented
__slots__: tuple[str, ...] = (source)

Undocumented

item = (source)

Undocumented