cpython: 7187d167abe8 (original) (raw)

--- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -10,7 +10,7 @@ -------------- -This module supports type hints as specified by :pep:484. The most +This module supports type hints as specified by :pep:484 and :pep:526. The most fundamental support consists of the type :class:Any, :class:Union, :class:Tuple, :class:Callable, :class:TypeVar, and :class:Generic. For full specification please see :pep:484. For @@ -62,10 +62,12 @@ Type aliases are useful for simplifying Note that None as a type hint is a special case and is replaced by type(None). +.. _distinct: + NewType ------- -Use the NewType helper function to create distinct types:: +Use the :func:NewType helper function to create distinct types:: from typing import NewType @@ -103,7 +105,7 @@ true at runtime. This also means that it is not possible to create a subtype of Derived since it is an identity function at runtime, not an actual type. Similarly, it -is not possible to create another NewType based on a Derived type:: +is not possible to create another :func:NewType based on a Derived type:: from typing import NewType @@ -533,10 +535,10 @@ The module defines the following classes but should also allow constructor calls in subclasses that match the constructor calls in the indicated base class. How the type checker is required to handle this particular case may change in future revisions of

@@ -577,7 +579,21 @@ The module defines the following classes A generic version of :class:collections.abc.Container. -.. class:: AbstractSet(Sized, Iterable[T_co], Container[T_co]) +.. class:: Hashable +

+.. class:: Sized +

+.. class:: Collection(Sized, Iterable[T_co], Container[T_co]) +

+.. class:: AbstractSet(Sized, Collection[T_co]) A generic version of :class:collections.abc.Set. @@ -585,7 +601,7 @@ The module defines the following classes A generic version of :class:collections.abc.MutableSet. -.. class:: Mapping(Sized, Iterable[KT], Container[KT], Generic[VT_co]) +.. class:: Mapping(Sized, Collection[KT], Generic[VT_co]) A generic version of :class:collections.abc.Mapping. @@ -593,7 +609,7 @@ The module defines the following classes A generic version of :class:collections.abc.MutableMapping. -.. class:: Sequence(Sized, Reversible[T_co], Container[T_co]) +.. class:: Sequence(Reversible[T_co], Collection[T_co]) A generic version of :class:collections.abc.Sequence. @@ -674,6 +690,10 @@ The module defines the following classes def get_position_in_index(word_list: Dict[str, int], word: str) -> int: return word_list[word] +.. class:: DefaultDict(collections.defaultdict, MutableMapping[KT, VT]) +

.. class:: Generator(Iterator[T_co], Generic[T_co, T_contra, V_co]) A generator can be annotated by the generic type @@ -769,6 +789,15 @@ The module defines the following classes are in the _fields attribute, which is part of the namedtuple API.) +.. function:: NewType(typ) +

+ .. function:: cast(typ, val) Cast a value to a type. @@ -780,12 +809,40 @@ The module defines the following classes .. function:: get_type_hints(obj)

+.. decorator:: overload +

+

.. decorator:: no_type_check(arg) Decorator to indicate that annotations are not type hints. @@ -802,3 +859,40 @@ The module defines the following classes This wraps the decorator with something that wraps the decorated function in :func:no_type_check. + +.. data:: ClassVar +

+

+

+.. data:: TYPE_CHECKING +

+