Skip to content

Commit dfa1113

Browse files
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 130717f) Co-authored-by: Michael Lee <[email protected]>
1 parent 3707bcf commit dfa1113

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Doc/library/typing.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ It is possible to declare the return type of a callable without specifying
169169
the call signature by substituting a literal ellipsis
170170
for the list of arguments in the type hint: ``Callable[..., ReturnType]``.
171171

172+
.. _generics:
173+
172174
Generics
173175
--------
174176

@@ -183,7 +185,7 @@ subscription to denote expected types for container elements.
183185
def notify_by_email(employees: Sequence[Employee],
184186
overrides: Mapping[str, str]) -> None: ...
185187

186-
Generics can be parametrized by using a new factory available in typing
188+
Generics can be parameterized by using a new factory available in typing
187189
called :class:`TypeVar`.
188190

189191
::
@@ -488,8 +490,9 @@ The module defines the following classes, functions and decorators:
488490
required to handle this particular case may change in future revisions of
489491
:pep:`484`.
490492

491-
The only legal parameters for :class:`Type` are classes, unions of classes, and
492-
:data:`Any`. For example::
493+
The only legal parameters for :class:`Type` are classes, :data:`Any`,
494+
:ref:`type variables <generics>`, and unions of any of these types.
495+
For example::
493496

494497
def new_non_team_user(user_class: Type[Union[BaseUser, ProUser]]): ...
495498

0 commit comments

Comments
 (0)