Skip to content

Commit

Permalink
Built-in generic now work without limitations (#1068)
Browse files Browse the repository at this point in the history
Closes: #1067
  • Loading branch information
srittau authored Feb 12, 2022
1 parent 9403ccf commit e982c96
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions docs/source/stubs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,20 @@ Type checkers support cyclic imports in stub files.
Built-in Generics
-----------------

PEP 585 [#pep585]_ built-in generics are generally supported, with
the following exceptions [#ts-4820]_:
PEP 585 [#pep585]_ built-in generics are supported and should be used instead
of the corresponding types from ``typing``::

* Built-in generics don't work in type aliases.
* Built-in generics don't work in base classes.
* ``type`` is not supported.
* Variable length tuples (``tuple[X, ...]``) are not supported.
from collections import defaultdict

In these cases, the appropriate types from ``typing`` must be used.
def foo(t: type[MyClass]) -> list[int]: ...
x: defaultdict[int]

Using imports from ``collections.abc`` instead of ``typing`` is
generally possible and recommended.
generally possible and recommended::

from collections.abc import Iterable

def foo(iter: Iterable[int]) -> None: ...

Unions
------
Expand Down Expand Up @@ -1102,7 +1104,6 @@ Bugs
----

.. [#ts-4819] typeshed issue #4819 -- PEP 604 tracker (https://github.com/python/typeshed/issues/4819)
.. [#ts-4820] typeshed issue #4820 -- PEP 585 tracker (https://github.com/python/typeshed/issues/4820)
.. [#ts-4913] typeshed issue #4913 -- PEP 613 tracker (https://github.com/python/typeshed/issues/4913)
.. [#ts-4972] typeshed issue #4972 -- PEP 570 tracker (https://github.com/python/typeshed/issues/4972)
Expand Down

0 comments on commit e982c96

Please sign in to comment.