Skip to content

Commit 63534a9

Browse files
authored
Replace typing_extensions -> typing in examples (#1987)
1 parent 9d613b1 commit 63534a9

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

docs/guides/unreachable.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ As an example, consider this simple calculator:
5454
.. code:: python
5555
5656
import enum
57-
from typing_extensions import Never
57+
from typing import Never
5858
5959
def assert_never(arg: Never) -> Never:
6060
raise AssertionError("Expected code to be unreachable")
@@ -72,6 +72,11 @@ As an example, consider this simple calculator:
7272
case _:
7373
assert_never(op)
7474
75+
.. note::
76+
77+
To use this feature on Python versions earlier than 3.11, you will need to
78+
import ``Never`` from ``typing_extensions`` (version 4.1 or newer).
79+
7580
The ``match`` statement covers all members of the ``Op`` enum,
7681
so the ``assert_never()`` call is unreachable and the type checker
7782
will accept this code. However, if you add another member to the

docs/reference/generics.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,7 @@ for a more faithful type annotation:
651651

652652
.. code-block:: python
653653
654-
from typing import Callable, TypeVar
655-
from typing_extensions import ParamSpec
654+
from typing import Callable, ParamSpec, TypeVar
656655
657656
P = ParamSpec('P')
658657
T = TypeVar('T')
@@ -663,13 +662,17 @@ for a more faithful type annotation:
663662
return func(*args, **kwds)
664663
return wrapper
665664
665+
.. note::
666+
667+
To use this feature on Python versions earlier than 3.10, you will need to
668+
import ``ParamSpec`` and ``Concatenate`` from ``typing_extensions``.
669+
666670
Parameter specifications also allow you to describe decorators that
667671
alter the signature of the input function:
668672

669673
.. code-block:: python
670674
671-
from typing import Callable, TypeVar
672-
from typing_extensions import ParamSpec
675+
from typing import Callable, ParamSpec, TypeVar
673676
674677
P = ParamSpec('P')
675678
T = TypeVar('T')
@@ -692,8 +695,7 @@ Or insert an argument:
692695

693696
.. code-block:: python
694697
695-
from typing import Callable, TypeVar
696-
from typing_extensions import Concatenate, ParamSpec
698+
from typing import Callable, Concatenate, ParamSpec, TypeVar
697699
698700
P = ParamSpec('P')
699701
T = TypeVar('T')
@@ -774,8 +776,7 @@ Example:
774776

775777
.. code-block:: python
776778
777-
from typing import TypeVar
778-
from typing_extensions import Protocol
779+
from typing import Protocol, TypeVar
779780
780781
T = TypeVar('T')
781782

docs/reference/protocols.rst

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ You can define your own protocol class by inheriting from the special
7171

7272
.. code-block:: python
7373
74-
from typing import Iterable
75-
from typing_extensions import Protocol
74+
from typing import Iterable, Protocol
7675
7776
class SupportsClose(Protocol):
7877
# Empty method body (explicit '...')
@@ -231,8 +230,7 @@ such as trees and linked lists:
231230

232231
.. code-block:: python
233232
234-
from typing import TypeVar, Optional
235-
from typing_extensions import Protocol
233+
from typing import TypeVar, Optional, Protocol
236234
237235
class TreeLike(Protocol):
238236
value: int
@@ -260,7 +258,7 @@ rudimentary support for runtime structural checks:
260258

261259
.. code-block:: python
262260
263-
from typing_extensions import Protocol, runtime_checkable
261+
from typing import Protocol, runtime_checkable
264262
265263
@runtime_checkable
266264
class Portable(Protocol):
@@ -303,8 +301,7 @@ member:
303301

304302
.. code-block:: python
305303
306-
from typing import Optional, Iterable
307-
from typing_extensions import Protocol
304+
from typing import Optional, Iterable, Protocol
308305
309306
class Combiner(Protocol):
310307
def __call__(self, *vals: bytes, maxlen: Optional[int] = None) -> list[bytes]: ...
@@ -328,8 +325,7 @@ a double underscore prefix is used. For example:
328325

329326
.. code-block:: python
330327
331-
from typing import Callable, TypeVar
332-
from typing_extensions import Protocol
328+
from typing import Callable, TypeVar, Protocol
333329
334330
T = TypeVar('T')
335331

docs/reference/quality.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ then the following file tests ``foo.py``:
4040

4141
.. code-block:: python
4242
43-
from typing_extensions import assert_type
43+
from typing import assert_type
4444
4545
assert_type(bar(42), str)
4646
47+
.. note::
48+
49+
To use this feature on Python versions earlier than 3.11, you will need to
50+
import ``assert_type`` from ``typing_extensions`` (version 4.2 or newer).
51+
4752
Clever use of ``mypy --warn-unused-ignores`` can be used to check that certain
4853
expressions are or are not well-typed. The idea is to have valid expressions along
4954
with invalid expressions annotated with ``type: ignore`` comments. When

0 commit comments

Comments
 (0)