module documentation

Classes for representing mypy types.

Class AnyType The type 'Any'.
Class CallableArgument Represents a Arg(type, 'name') inside a Callable's type list.
Class CallableType Type of a non-overloaded callable object (such as function).
Class DeletedType Type of deleted variables.
Class EllipsisType The type ... (ellipsis).
Class ErasedType Placeholder for an erased type.
Class ExtraAttrs Summary of module attributes and types.
Class FormalArgument Undocumented
Class FunctionLike Abstract base class for function types.
Class HasRecursiveType Undocumented
Class HasTypeVars Undocumented
Class Instance An instance type of form C[T1, ..., Tn].
Class InstantiateAliasVisitor Undocumented
Class LiteralType The type of a Literal instance. Literal[Value]
Class LocationSetter Undocumented
Class NoneType The type of 'None'.
Class Overloaded Overloaded function type T1, ... Tn, where each Ti is CallableType.
Class Parameters Type that represents the parameters to a function.
Class ParamSpecFlavor Undocumented
Class ParamSpecType Type that refers to a ParamSpec.
Class PartialType Type such as List[?] where type arguments are unknown, or partial None type.
Class PlaceholderType Temporary, yet-unknown type during semantic analysis.
Class ProperType Not a type alias.
Class RawExpressionType A synthetic type representing some arbitrary expression that does not cleanly translate into a type.
Class RequiredType Required[T] or NotRequired[T]. Only usable at top-level of a TypedDict definition.
Class TrivialSyntheticTypeTranslator A base class for type translators that need to be run during semantic analysis.
Class TupleType The tuple type Tuple[T1, ..., Tn] (at least one type argument).
Class Type Abstract base class for all types.
Class TypeAliasType A type alias to another type.
Class TypedDictType Type of TypedDict object {'k1': v1, ..., 'kn': vn}.
Class TypeGuardedType Only used by find_isinstance_check() etc.
Class TypeList Information about argument types and names [...].
Class TypeOfAny This class describes different types of Any. Each 'Any' can be of only one type at a time.
Class TypeStrVisitor Visitor for pretty-printing types into strings.
Class TypeType For types like Type[User].
Class TypeVarId Undocumented
Class TypeVarLikeType Undocumented
Class TypeVarTupleType Type that refers to a TypeVarTuple.
Class TypeVarType Type that refers to a type variable.
Class UnboundType Instance type that has not been bound during semantic analysis.
Class UninhabitedType This type has no members.
Class UnionType The union type Union[T1, ..., Tn] (at least one type argument).
Class UnpackType Type operator Unpack from PEP646. Can be either with Unpack[] or unpacking * syntax.
Class UnrollAliasVisitor Undocumented
Function bad_type_type_item Prohibit types like Type[Type[...]].
Function callable_with_ellipsis Construct type Callable[..., ret_type].
Function deserialize_type Undocumented
Function expand_param_spec This is shared part of the logic w.r.t. ParamSpec instantiation.
Function flatten_nested_unions Flatten nested unions in a type list.
Function get_proper_type Get the expansion of a type alias type.
Function get_proper_types Undocumented
Function has_recursive_types Check if a type contains any recursive aliases (recursively).
Function has_type_vars Check if a type contains any type variables (recursively).
Function invalid_recursive_alias Flag aliases like A = Union[int, A] (and similar mutual aliases).
Function is_generic_instance Undocumented
Function is_literal_type Check if this type is a LiteralType with the given fallback type and value.
Function is_named_instance Undocumented
Function is_optional Undocumented
Function is_self_type_like Does this look like a self-type annotation?
Function is_union_with_any Is this a union with Any or a plain Any type?
Function remove_optional Undocumented
Function remove_trivial Make trivial simplifications on a list of types without calling is_subtype().
Function replace_alias_tvars Replace type variables in a generic type alias tp with substitutions subs resetting context. Length of subs should be already checked.
Function store_argument_type Undocumented
Function strip_type Make a copy of type without 'debugging info' (function name).
Constant ANNOTATED_TYPE_NAMES Undocumented
Constant ASSERT_TYPE_NAMES Undocumented
Constant DATACLASS_TRANSFORM_NAMES Undocumented
Constant deserialize_map Undocumented
Constant ENUM_REMOVED_PROPS Undocumented
Constant FINAL_DECORATOR_NAMES Undocumented
Constant FINAL_TYPE_NAMES Undocumented
Constant LITERAL_TYPE_NAMES Undocumented
Constant MYPYC_NATIVE_INT_NAMES Undocumented
Constant names Undocumented
Constant NEVER_NAMES Undocumented
Constant NOT_READY Undocumented
Constant OVERLOAD_NAMES Undocumented
Constant PROTOCOL_NAMES Undocumented
Constant REVEAL_TYPE_NAMES Undocumented
Constant TPDICT_FB_NAMES Undocumented
Constant TPDICT_NAMES Undocumented
Constant TUPLE_LIKE_INSTANCE_NAMES Undocumented
Constant TYPE_ALIAS_NAMES Undocumented
Constant TYPED_NAMEDTUPLE_NAMES Undocumented
Type Variable CT Undocumented
Type Variable T Undocumented
Type Alias JsonDict Undocumented
Type Alias LiteralValue Undocumented
Variable NormalizedCallableType Undocumented
Function _flattened Undocumented
Constant _dummy Undocumented
Constant _dummy_int Undocumented
Constant _has_recursive_type Undocumented
def bad_type_type_item(item: Type) -> bool: (source)

Prohibit types like Type[Type[...]]. Such types are explicitly prohibited by PEP 484. Also they cause problems with recursive types like T = Type[T], because internal representation of TypeType item is normalized (i.e. always a proper type).

def callable_with_ellipsis(any_type: AnyType, ret_type: Type, fallback: Instance) -> CallableType: (source)

Construct type Callable[..., ret_type].

def deserialize_type(data: JsonDict|str) -> Type: (source)

Undocumented

This is shared part of the logic w.r.t. ParamSpec instantiation. It is shared between type aliases and proper types, that currently use somewhat different logic for instantiation.

def flatten_nested_unions(types: Sequence[Type], handle_type_alias_type: bool = True) -> list[Type]: (source)

Flatten nested unions in a type list.

@overload
def get_proper_type(typ: None):
@overload
def get_proper_type(typ: Type) -> ProperType:
(source)

Get the expansion of a type alias type. If the type is already a proper type, this is a no-op. Use this function wherever a decision is made on a call like e.g. 'if isinstance(typ, UnionType): ...', because 'typ' in this case may be an alias to union. Note: if after making the decision on the isinstance() call you pass on the original type (and not one of its components) it is recommended to *always* pass on the unexpanded alias.

@overload
def get_proper_types(types: list[Type]|tuple[Type, ...]) -> list[ProperType]:
@overload
def get_proper_types(types: list[Type|None]|tuple[Type|None, ...]) -> list[ProperType|None]:
(source)

Undocumented

def has_recursive_types(typ: Type) -> bool: (source)

Check if a type contains any recursive aliases (recursively).

def has_type_vars(typ: Type) -> bool: (source)

Check if a type contains any type variables (recursively).

def invalid_recursive_alias(seen_nodes: set[mypy.nodes.TypeAlias], target: Type) -> bool: (source)

Flag aliases like A = Union[int, A] (and similar mutual aliases). Such aliases don't make much sense, and cause problems in later phases.

def is_generic_instance(tp: Type) -> bool: (source)

Undocumented

def is_literal_type(typ: ProperType, fallback_fullname: str, value: LiteralValue) -> bool: (source)

Check if this type is a LiteralType with the given fallback type and value.

def is_named_instance(t: Type, fullnames: str|tuple[str, ...]) -> TypeGuard[Instance]: (source)

Undocumented

def is_optional(t: Type) -> bool: (source)

Undocumented

def is_self_type_like(typ: Type, *, is_classmethod: bool) -> bool: (source)

Does this look like a self-type annotation?

def is_union_with_any(tp: Type) -> bool: (source)

Is this a union with Any or a plain Any type?

def remove_optional(typ: Type) -> Type: (source)

Undocumented

def remove_trivial(types: Iterable[Type]) -> list[Type]: (source)

Make trivial simplifications on a list of types without calling is_subtype(). This makes following simplifications: * Remove bottom types (taking into account strict optional setting) * Remove everything else if there is an `object` * Remove strict duplicate types

def replace_alias_tvars(tp: Type, vars: list[TypeVarLikeType], subs: list[Type], newline: int, newcolumn: int) -> Type: (source)

Replace type variables in a generic type alias tp with substitutions subs resetting context. Length of subs should be already checked.

def store_argument_type(defn: FuncItem, i: int, typ: CallableType, named_type: Callable[[str, list[Type]], Instance]): (source)

Undocumented

def strip_type(typ: Type) -> Type: (source)

Make a copy of type without 'debugging info' (function name).

ANNOTATED_TYPE_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.Annotated', 'typing_extensions.Annotated')
ASSERT_TYPE_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.assert_type', 'typing_extensions.assert_type')
DATACLASS_TRANSFORM_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.dataclass_transform', 'typing_extensions.dataclass_transform')
deserialize_map = (source)

Undocumented

Value
{key: obj.deserialize for key, obj in names.items() if isinstance(obj, type
    ) and issubclass(obj, Type) and obj is not Type}
ENUM_REMOVED_PROPS: tuple[str, ...] = (source)

Undocumented

Value
('_ignore_', '_order_', '__order__')
FINAL_DECORATOR_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.final', 'typing_extensions.final')
FINAL_TYPE_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.Final', 'typing_extensions.Final')
LITERAL_TYPE_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.Literal', 'typing_extensions.Literal')
MYPYC_NATIVE_INT_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('mypy_extensions.i64', 'mypy_extensions.i32')

Undocumented

Value
globals().copy()
NEVER_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.NoReturn',
 'typing_extensions.NoReturn',
 'mypy_extensions.NoReturn',
 'typing.Never',
 'typing_extensions.Never')
NOT_READY = (source)

Undocumented

Value
mypy.nodes.FakeInfo('De-serialization failure: TypeInfo not fixed')
OVERLOAD_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.overload', 'typing_extensions.overload')
PROTOCOL_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.Protocol', 'typing_extensions.Protocol')
REVEAL_TYPE_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('builtins.reveal_type', 'typing.reveal_type', 'typing_extensions.reveal_type')
TPDICT_FB_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing._TypedDict',
 'typing_extensions._TypedDict',
 'mypy_extensions._TypedDict')
TPDICT_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.TypedDict', 'typing_extensions.TypedDict', 'mypy_extensions.TypedDict')
TUPLE_LIKE_INSTANCE_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('builtins.tuple',
 'typing.Iterable',
 'typing.Container',
 'typing.Sequence',
 'typing.Reversible')
TYPE_ALIAS_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.TypeAlias', 'typing_extensions.TypeAlias')
TYPED_NAMEDTUPLE_NAMES: tuple[str, ...] = (source)

Undocumented

Value
('typing.NamedTuple', 'typing_extensions.NamedTuple')

Undocumented

Value
TypeVar('CT',
        bound='CallableType')

Undocumented

Value
TypeVar('T')
JsonDict: _TypeAlias = (source)

Undocumented

Value
Dict[str, Any]
LiteralValue: _TypeAlias = (source)

Undocumented

Value
Union[int, str, bool, float]
NormalizedCallableType = (source)

Undocumented

def _flattened(types: Iterable[Type]) -> Iterable[Type]: (source)

Undocumented

Undocumented

Value
object()
_dummy_int: int = (source)

Undocumented

Value
-999999
_has_recursive_type = (source)

Undocumented

Value
HasRecursiveType()