class TypeType(ProperType): (source)
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 |
Undocumented
Parameters | |
item:Type | Undocumented |
line:int | Undocumented |
column:int | Undocumented |
Returns | |
ProperType | Undocumented |
mypy.types.Type.__init__
Parameters | |
item:Bogus[ | Undocumented |
line:int | Undocumented |
column:int | Undocumented |
mypy.types.Type.accept
Undocumented
Parameters | |
visitor:TypeVisitor[ | Undocumented |
Returns | |
T | Undocumented |