PyDocs

Development Tools

typing

The typing module: Support for gradual typing as defined by PEP 484 and subsequent PEPs.

Among other things, the module includes the following:
* Generic, Protocol, and internal machinery to support generic aliases.
  All subscripted types like X[int], Union[int, str] are generic aliases.
* Various "special forms" that have unique meanings in type annotations:
  Any, Never, ClassVar, Self, Concatenate, Unpack, and others.
* Classes whose instances can be type arguments to generic classes and functions:
  TypeVar, ParamSpec, TypeVarTuple.
* Public helper functions: get_type_hints, overload, cast, final, and others.
* Several protocols to support duck-typing:
  SupportsFloat, SupportsIndex, SupportsAbs, and others.
* Special types: NewType, NamedTuple, TypedDict.
* Deprecated aliases for builtin types and collections.abc ABCs.

Any name not present in __all__ is an implementation detail
that may be changed without notice. Use at your own risk!
Symbols in typing

a

AbstractSet
Deprecated alias to collections.abc.Set.
Annotated
Add context-specific metadata to a type.
Any
Special type indicating an unconstrained type.
AnyStr
A constrained type variable.
assert_never
Statically assert that a line of code is unreachable.
assert_type
Ask a static type checker to confirm that the value is of the given type.
AsyncContextManager
Deprecated alias to contextlib.AbstractAsyncContextManager.
AsyncGenerator
Deprecated alias to collections.abc.AsyncGenerator.
AsyncIterable
Deprecated alias to collections.abc.AsyncIterable.
AsyncIterator
Deprecated alias to collections.abc.AsyncIterator.
Awaitable
Deprecated alias to collections.abc.Awaitable.

b

BinaryIO
Typed approximation of the return of open() in binary mode.
ByteString
Deprecated alias to collections.abc.ByteString.

c

Callable
Deprecated alias to collections.abc.Callable.
cast
Cast a value to a type.
ChainMap
Deprecated alias to collections.ChainMap.
ClassVar
Special type construct to mark class variables.
clear_overloads
Clear all overloads in the registry.
Collection
Deprecated alias to collections.abc.Collection.
Concatenate
Special form for annotating higher-order functions.
Container
Deprecated alias to collections.abc.Container.
ContextManager
Deprecated alias to contextlib.AbstractContextManager.
Coroutine
Deprecated alias to collections.abc.Coroutine.
Counter
Deprecated alias to collections.Counter.

d

dataclass_transform
Decorator to mark an object as providing dataclass-like behavior.
DefaultDict
Deprecated alias to collections.defaultdict.
Deque
Deprecated alias to collections.deque.
Dict
Deprecated alias to dict.
disjoint_base
This decorator marks a class as a disjoint base.

e

evaluate_forward_ref
Evaluate a forward reference as a type hint.

f

final
Decorator to indicate final methods and final classes.
Final
Special typing construct to indicate final names to type checkers.
ForwardRef
Wrapper that holds a forward reference.
FrozenSet
Deprecated alias to frozenset.

g

Generator
Deprecated alias to collections.abc.Generator.
Generic
Abstract base class for generic types.
get_args
Get type arguments with all substitutions performed.
get_origin
Get the unsubscripted version of a type.
get_overloads
Return all defined overloads for *func* as a sequence.
get_protocol_members
Return the set of members defined in a Protocol.
get_type_hints
Return type hints for an object.

h

Hashable
Deprecated alias to collections.abc.Hashable.

i

IO
Generic base class for TextIO and BinaryIO.
is_protocol
Return True if the given type is a Protocol.
is_typeddict
Check if an object is a TypedDict class.
ItemsView
Deprecated alias to collections.abc.ItemsView.
Iterable
Deprecated alias to collections.abc.Iterable.
Iterator
Deprecated alias to collections.abc.Iterator.

k

KeysView
Deprecated alias to collections.abc.KeysView.

l

List
Deprecated alias to list.
Literal
Special typing form to define literal types (a.k.a.
LiteralString
Represents an arbitrary literal string.

m

Mapping
Deprecated alias to collections.abc.Mapping.
MappingView
Deprecated alias to collections.abc.MappingView.
Match
Deprecated alias to re.Match.
MutableMapping
Deprecated alias to collections.abc.MutableMapping.
MutableSequence
Deprecated alias to collections.abc.MutableSequence.
MutableSet
Deprecated alias to collections.abc.MutableSet.

n

NamedTuple
Typed version of collections.namedtuple.
Never
The bottom type, a type that has no members.
NewType
NewType creates simple unique types with almost zero runtime overhead.
no_type_check
Decorator to indicate that annotations are not type hints.
NoDefault
A sentinel object used to indicate that a type parameter has no default value.
NoExtraItems
A sentinel object used to indicate that a TypedDict does not have the extra_items class argument.
NoReturn
Special type indicating functions that never return.
NotRequired
Special typing construct to mark a TypedDict key as potentially missing.

o

Optional
Optional[X] is equivalent to X | None.
OrderedDict
Deprecated alias to collections.OrderedDict.
overload
Decorator for overloaded functions/methods.
override
Indicate that a method is intended to override a method in a base class.

p

ParamSpec
Parameter specification variable.
ParamSpecArgs
The args for a ParamSpec object.
ParamSpecKwargs
The kwargs for a ParamSpec object.
Pattern
Deprecated alias to re.Pattern.
Protocol
Base class for protocol classes.

r

ReadOnly
A special typing construct to mark an item of a TypedDict as read-only.
Required
Special typing construct to mark a TypedDict key as required.
reveal_type
Ask a static type checker to reveal the inferred type of an expression.
Reversible
Deprecated alias to collections.abc.Reversible.
runtime_checkable
Mark a protocol class as a runtime protocol.

s

Self
Used to spell the type of "self" in classes.
Sequence
Deprecated alias to collections.abc.Sequence.
Set
Deprecated alias to set.
Sized
Deprecated alias to collections.abc.Sized.
SupportsAbs
A protocol with one abstract method __abs__ that is covariant in its return type.
SupportsBytes
A protocol with one abstract method __bytes__.
SupportsComplex
A protocol with one abstract method __complex__.
SupportsFloat
A protocol with one abstract method __float__.
SupportsIndex
A protocol with one abstract method __index__.
SupportsInt
A protocol with one abstract method __int__.
SupportsRound
A protocol with one abstract method __round__ that is covariant in its return type.

t

Text
Create a new string object from the given object.
TextIO
Typed approximation of the return of open() in text mode.
Tuple
Deprecated alias to builtins.tuple.
Type
Deprecated alias to builtins.type.
type_check_only
Decorator to mark a class or function as unavailable at runtime.
TYPE_CHECKING
A special constant that is assumed to be True by static type checkers.
TypeAlias
Special form for marking type aliases.
TypeAliasType
Type alias.
TypedDict
A simple typed namespace.
TypeForm
A special form representing the value that results from the evaluation of a type expression.
TypeGuard
Special typing construct for marking user-defined type predicate functions.
TypeIs
Special typing construct for marking user-defined type predicate functions.
TypeVar
Type variable.
TypeVarTuple
Type variable tuple.

u

Union
Represent a union type
Unpack
Type unpack operator.

v

ValuesView
Deprecated alias to collections.abc.ValuesView.