diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-09-26 15:23:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-26 15:23:23 (GMT) |
commit | dfa11135ce53967ac97550d0a9343d32c9958ac0 (patch) | |
tree | d704ee2c75515358a866db4904a336df42624fe8 | |
parent | 3707bcf02b7574448d7137935995146f6e8ea810 (diff) | |
download | cpython-dfa11135ce53967ac97550d0a9343d32c9958ac0.zip cpython-dfa11135ce53967ac97550d0a9343d32c9958ac0.tar.gz cpython-dfa11135ce53967ac97550d0a9343d32c9958ac0.tar.bz2 |
Clarify that Type[SomeTypeVar] is legal (GH-9585)
Currently, the docs state that when doing `Type[X]`, X is only allowed to
be a class, a union of classes, and Any. This pull request amends
that sentence to clarify X may also be a typevar (or a union involving
classes, Any, and TypeVars).
(cherry picked from commit 130717fe58abb2ab9e7938207df0c130a2562747)
Co-authored-by: Michael Lee <michael.lee.0x2a@gmail.com>
-rw-r--r-- | Doc/library/typing.rst | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 91d8a5f..e80cd3f 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -169,6 +169,8 @@ It is possible to declare the return type of a callable without specifying the call signature by substituting a literal ellipsis for the list of arguments in the type hint: ``Callable[..., ReturnType]``. +.. _generics: + Generics -------- @@ -183,7 +185,7 @@ subscription to denote expected types for container elements. def notify_by_email(employees: Sequence[Employee], overrides: Mapping[str, str]) -> None: ... -Generics can be parametrized by using a new factory available in typing +Generics can be parameterized by using a new factory available in typing called :class:`TypeVar`. :: @@ -488,8 +490,9 @@ The module defines the following classes, functions and decorators: required to handle this particular case may change in future revisions of :pep:`484`. - The only legal parameters for :class:`Type` are classes, unions of classes, and - :data:`Any`. For example:: + The only legal parameters for :class:`Type` are classes, :data:`Any`, + :ref:`type variables <generics>`, and unions of any of these types. + For example:: def new_non_team_user(user_class: Type[Union[BaseUser, ProUser]]): ... |