Перейти к содержанию

typing — Support for type hints

Documentation: https://docs.python.org/3/library/typing.html#module-typing

PEP 585

PEP 585 — Type Hinting Generics In Standard Collections.

This PEP proposes to enable support for the generics syntax in all standard collections currently available in the typing module.

Starting with Python 3.9, the following collections become generic1 and importing those from typing is deprecated:

tuple # typing.Tuple
list # typing.List
dict # typing.Dict
set # typing.Set
frozenset # typing.FrozenSet
type # typing.Type
collections.deque
collections.defaultdict
collections.OrderedDict
collections.Counter
collections.ChainMap
collections.abc.Awaitable
collections.abc.Coroutine
collections.abc.AsyncIterable
collections.abc.AsyncIterator
collections.abc.AsyncGenerator
collections.abc.Iterable
collections.abc.Iterator
collections.abc.Generator
collections.abc.Reversible
collections.abc.Container
collections.abc.Collection
collections.abc.Callable
collections.abc.Set # typing.AbstractSet
collections.abc.MutableSet
collections.abc.Mapping
collections.abc.MutableMapping
collections.abc.Sequence
collections.abc.MutableSequence
collections.abc.ByteString
collections.abc.MappingView
collections.abc.KeysView
collections.abc.ItemsView
collections.abc.ValuesView
contextlib.AbstractContextManager # typing.ContextManager
contextlib.AbstractAsyncContextManager # typing.AsyncContextManager
re.Pattern # typing.Pattern, typing.re.Pattern
re.Match # typing.Match, typing.re.Match


  1. Generic — a type that can be parameterized, typically a container. Also known as a parametric type or a generic type. For example: dict. Parameterized generic — a specific instance of a generic with the expected types for container elements provided. Also known as a parameterized type. For example: dict[str, int]