Skip to content

Commit f30ced1

Browse files
author
Guido van Rossum
committed
Improve wording on covariance of Type[] (Ivan L, #107).
1 parent 39c07e8 commit f30ced1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pep-0484.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ Note that it is legal to use a union of classes as the parameter for
914914
``Type[]``, as in::
915915

916916
def new_non_team_user(user_class: Type[Union[BasicUser, ProUser]]):
917+
user = new_user(user_class)
917918
...
918919

919920
However the actual argument passed in at runtime must still be a
@@ -952,8 +953,12 @@ attributes and methods defined by ``type`` (for example,
952953
``__repr__()`` and ``__mro__``). Such a variable can be called with
953954
arbitrary arguments, and the return type is ``Any``.
954955

955-
``Type[T]`` should be considered covariant, since for a concrete class
956-
``C``, ``Type[C]`` matches ``C`` and any of its subclasses.
956+
``Type`` is covariant in its parameter, because ``Type[Derived]`` is a
957+
subtype of ``Type[Base]``::
958+
959+
def new_pro_user(pro_user_class: Type[ProUser]):
960+
user = new_user(pro_user_class) # OK
961+
...
957962

958963

959964
Version and platform checking

0 commit comments

Comments
 (0)