summaryrefslogtreecommitdiff
path: root/Doc/library/typing.rst
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-11-25 19:47:43 +0300
committerBerker Peksag <berker.peksag@gmail.com>2016-11-25 19:47:43 +0300
commit1b442440d5eb6f80f9d6d167fcf6c39486aa707a (patch)
tree595d7cd26ee2fcfacd52a048030273d887292ff3 /Doc/library/typing.rst
parente37c454724656ce5b04fac36c672d760c4c18c37 (diff)
parent4a5e10c5907eaa5f3ade471ea71cad3368f0614c (diff)
downloadcpython-1b442440d5eb6f80f9d6d167fcf6c39486aa707a.tar.gz
Issue #28738: Merge from 3.6
Diffstat (limited to 'Doc/library/typing.rst')
-rw-r--r--Doc/library/typing.rst43
1 files changed, 32 insertions, 11 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 0316f01958..2446b4b8f0 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -10,8 +10,8 @@
--------------
-This module supports type hints as specified by :pep:`484`. The most
-fundamental support consists of the types :data:`Any`, :data:`Union`,
+This module supports type hints as specified by :pep:`484` and :pep:`526`.
+The most fundamental support consists of the types :data:`Any`, :data:`Union`,
:data:`Tuple`, :data:`Callable`, :class:`TypeVar`, and
:class:`Generic`. For full specification please see :pep:`484`. For
a simplified introduction to type hints see :pep:`483`.
@@ -523,7 +523,13 @@ The module defines the following classes, functions and decorators:
An alias to :class:`collections.abc.Sized`
-.. class:: AbstractSet(Sized, Iterable[T_co], Container[T_co])
+.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
+
+ A generic version of :class:`collections.abc.Collection`
+
+ .. versionadded:: 3.6
+
+.. class:: AbstractSet(Sized, Collection[T_co])
A generic version of :class:`collections.abc.Set`.
@@ -531,7 +537,7 @@ The module defines the following classes, functions and decorators:
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`.
@@ -539,7 +545,7 @@ The module defines the following classes, functions and decorators:
A generic version of :class:`collections.abc.MutableMapping`.
-.. class:: Sequence(Sized, Iterable[T_co], Container[T_co])
+.. class:: Sequence(Reversible[T_co], Collection[T_co])
A generic version of :class:`collections.abc.Sequence`.
@@ -623,6 +629,12 @@ The module defines the following classes, functions and decorators:
A generic version of :class:`collections.abc.AsyncIterator`.
+.. class:: ContextManager(Generic[T_co])
+
+ A generic version of :class:`contextlib.AbstractContextManager`.
+
+ .. versionadded:: 3.6
+
.. class:: Dict(dict, MutableMapping[KT, VT])
A generic version of :class:`dict`.
@@ -698,23 +710,32 @@ The module defines the following classes, functions and decorators:
``Pattern[str]``, ``Pattern[bytes]``, ``Match[str]``, or
``Match[bytes]``.
-.. function:: NamedTuple(typename, fields)
+.. class:: NamedTuple
Typed version of namedtuple.
Usage::
- Employee = typing.NamedTuple('Employee', [('name', str), ('id', int)])
+ class Employee(NamedTuple):
+ name: str
+ id: int
This is equivalent to::
Employee = collections.namedtuple('Employee', ['name', 'id'])
- The resulting class has one extra attribute: _field_types,
+ The resulting class has one extra attribute: ``_field_types``,
giving a dict mapping field names to types. (The field names
- are in the _fields attribute, which is part of the namedtuple
+ are in the ``_fields`` attribute, which is part of the namedtuple
API.)
+ Backward-compatible usage::
+
+ Employee = NamedTuple('Employee', [('name', str), ('id', int)])
+
+ .. versionchanged:: 3.6
+ Added support for :pep:`526` variable annotation syntax.
+
.. function:: NewType(typ)
A helper function to indicate a distinct types to a typechecker,
@@ -884,8 +905,8 @@ The module defines the following classes, functions and decorators:
and should not be set on instances of that class. Usage::
class Starship:
- stats = {} # type: ClassVar[Dict[str, int]] # class variable
- damage = 10 # type: int # instance variable
+ stats: ClassVar[Dict[str, int]] = {} # class variable
+ damage: int = 10 # instance variable
:data:`ClassVar` accepts only types and cannot be further subscribed.