Skip to content

Commit 02c50bc

Browse files
rdimaioAlexWaygood
andauthored
Docs: Update TypedDict import statements (#16958)
Since Python 3.8, `TypedDict` has been available from the `typing` module. As Python 3.8+ is needed to use mypy (https://github.com/python/mypy/blob/master/setup.py#L12), then it's best for the docs to reflect Python 3.8+ usage. For previous versions, there's already a disclaimer on the page that explains that `typing_extensions` must be used: https://github.com/python/mypy/blob/master/docs/source/typed_dict.rst?plain=1#L102-L110 Co-authored-by: Alex Waygood <[email protected]>
1 parent f19b5d3 commit 02c50bc

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

docs/source/common_issues.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ Consider this example:
541541

542542
.. code-block:: python
543543
544-
from typing_extensions import Protocol
544+
from typing import Protocol
545545
546546
class P(Protocol):
547547
x: float
@@ -561,7 +561,7 @@ the protocol definition:
561561

562562
.. code-block:: python
563563
564-
from typing_extensions import Protocol
564+
from typing import Protocol
565565
566566
class P(Protocol):
567567
@property

docs/source/error_code_list.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ Example:
537537

538538
.. code-block:: python
539539
540-
from typing_extensions import TypedDict
540+
from typing import TypedDict
541541
542542
class Point(TypedDict):
543543
x: int
@@ -562,7 +562,7 @@ to have been validated at the point of construction. Example:
562562

563563
.. code-block:: python
564564
565-
from typing_extensions import TypedDict
565+
from typing import TypedDict
566566
567567
class Point(TypedDict):
568568
x: int
@@ -868,7 +868,7 @@ the return type affects which lines mypy thinks are reachable after a
868868
``True`` may swallow exceptions. An imprecise return type can result
869869
in mysterious errors reported near ``with`` statements.
870870

871-
To fix this, use either ``typing_extensions.Literal[False]`` or
871+
To fix this, use either ``typing.Literal[False]`` or
872872
``None`` as the return type. Returning ``None`` is equivalent to
873873
returning ``False`` in this context, since both are treated as false
874874
values.
@@ -897,7 +897,7 @@ You can use ``Literal[False]`` to fix the error:
897897

898898
.. code-block:: python
899899
900-
from typing_extensions import Literal
900+
from typing import Literal
901901
902902
class MyContext:
903903
...

docs/source/generics.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ protocols mostly follow the normal rules for generic classes. Example:
770770

771771
.. code-block:: python
772772
773-
from typing import TypeVar
774-
from typing_extensions import Protocol
773+
from typing import Protocol, TypeVar
775774
776775
T = TypeVar('T')
777776

docs/source/protocols.rst

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class:
6868

6969
.. code-block:: python
7070
71-
from typing import Iterable
72-
from typing_extensions import Protocol
71+
from typing import Iterable, Protocol
7372
7473
class SupportsClose(Protocol):
7574
# Empty method body (explicit '...')
@@ -226,8 +225,7 @@ such as trees and linked lists:
226225

227226
.. code-block:: python
228227
229-
from typing import TypeVar, Optional
230-
from typing_extensions import Protocol
228+
from typing import TypeVar, Optional, Protocol
231229
232230
class TreeLike(Protocol):
233231
value: int
@@ -255,7 +253,7 @@ rudimentary support for runtime structural checks:
255253

256254
.. code-block:: python
257255
258-
from typing_extensions import Protocol, runtime_checkable
256+
from typing import Protocol, runtime_checkable
259257
260258
@runtime_checkable
261259
class Portable(Protocol):
@@ -298,8 +296,7 @@ member:
298296

299297
.. code-block:: python
300298
301-
from typing import Optional, Iterable
302-
from typing_extensions import Protocol
299+
from typing import Optional, Iterable, Protocol
303300
304301
class Combiner(Protocol):
305302
def __call__(self, *vals: bytes, maxlen: Optional[int] = None) -> list[bytes]: ...
@@ -323,8 +320,7 @@ a double underscore prefix is used. For example:
323320

324321
.. code-block:: python
325322
326-
from typing import Callable, TypeVar
327-
from typing_extensions import Protocol
323+
from typing import Callable, Protocol, TypeVar
328324
329325
T = TypeVar('T')
330326

docs/source/stubs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ For example:
114114

115115
.. code-block:: python
116116
117-
from typing_extensions import Protocol
117+
from typing import Protocol
118118
119119
class Resource(Protocol):
120120
def ok_1(self, foo: list[str] = ...) -> None: ...

docs/source/typed_dict.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dictionary value depends on the key:
2525

2626
.. code-block:: python
2727
28-
from typing_extensions import TypedDict
28+
from typing import TypedDict
2929
3030
Movie = TypedDict('Movie', {'name': str, 'year': int})
3131
@@ -189,7 +189,7 @@ in Python 3.6 and later:
189189

190190
.. code-block:: python
191191
192-
from typing_extensions import TypedDict
192+
from typing import TypedDict # "from typing_extensions" in Python 3.7 and earlier
193193
194194
class Movie(TypedDict):
195195
name: str

0 commit comments

Comments
 (0)