Skip to content

Commit

Permalink
Docs: Python 3.8, Update typing_extensions imports to typing
Browse files Browse the repository at this point in the history
  • Loading branch information
rdimaio committed Feb 29, 2024
1 parent 6fe6a78 commit 8453b10
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/source/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ Consider this example:

.. code-block:: python
from typing_extensions import Protocol
from typing import Protocol
class P(Protocol):
x: float
Expand All @@ -561,7 +561,7 @@ the protocol definition:

.. code-block:: python
from typing_extensions import Protocol
from typing import Protocol
class P(Protocol):
@property
Expand Down
10 changes: 5 additions & 5 deletions docs/source/error_code_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ Example:

.. code-block:: python
from typing_extensions import TypedDict
from typing import TypedDict
class Point(TypedDict):
x: int
Expand All @@ -562,7 +562,7 @@ to have been validated at the point of construction. Example:

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

To fix this, use either ``typing_extensions.Literal[False]`` or
To fix this, use either ``typing.Literal[False]`` or
``None`` as the return type. Returning ``None`` is equivalent to
returning ``False`` in this context, since both are treated as false
values.
Expand All @@ -888,7 +888,7 @@ This produces the following output from mypy:
.. code-block:: text
example.py:3: error: "bool" is invalid as return type for "__exit__" that always returns False
example.py:3: note: Use "typing_extensions.Literal[False]" as the return type or change it to
example.py:3: note: Use "typing.Literal[False]" as the return type or change it to
"None"
example.py:3: note: If return type of "__exit__" implies that it may return True, the context
manager may swallow exceptions
Expand All @@ -897,7 +897,7 @@ You can use ``Literal[False]`` to fix the error:

.. code-block:: python
from typing_extensions import Literal
from typing import Literal
class MyContext:
...
Expand Down
2 changes: 1 addition & 1 deletion docs/source/error_code_list2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ Correct usage:
.. code-block:: python
# Use "mypy --enable-error-code unimported-reveal"
from typing import reveal_type # or `typing_extensions`
from typing import reveal_type # "from typing_extensions" in Python 3.10 and earlier
x = 1
# This won't raise an error:
Expand Down
3 changes: 1 addition & 2 deletions docs/source/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,7 @@ protocols mostly follow the normal rules for generic classes. Example:

.. code-block:: python
from typing import TypeVar
from typing_extensions import Protocol
from typing import Protocol, TypeVar
T = TypeVar('T')
Expand Down
14 changes: 5 additions & 9 deletions docs/source/protocols.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class:

.. code-block:: python
from typing import Iterable
from typing_extensions import Protocol
from typing import Iterable, Protocol
class SupportsClose(Protocol):
# Empty method body (explicit '...')
Expand Down Expand Up @@ -226,8 +225,7 @@ such as trees and linked lists:

.. code-block:: python
from typing import TypeVar, Optional
from typing_extensions import Protocol
from typing import TypeVar, Optional, Protocol
class TreeLike(Protocol):
value: int
Expand Down Expand Up @@ -255,7 +253,7 @@ rudimentary support for runtime structural checks:

.. code-block:: python
from typing_extensions import Protocol, runtime_checkable
from typing import Protocol, runtime_checkable
@runtime_checkable
class Portable(Protocol):
Expand Down Expand Up @@ -298,8 +296,7 @@ member:

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

.. code-block:: python
from typing import Callable, TypeVar
from typing_extensions import Protocol
from typing import Callable, Protocol, TypeVar
T = TypeVar('T')
Expand Down
2 changes: 1 addition & 1 deletion docs/source/stubs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ For example:

.. code-block:: python
from typing_extensions import Protocol
from typing import Protocol
class Resource(Protocol):
def ok_1(self, foo: list[str] = ...) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion docs/source/typed_dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ in Python 3.6 and later:

.. code-block:: python
from typing import TypedDict
from typing import TypedDict # "from typing_extensions" in Python 3.7 and earlier
class Movie(TypedDict):
name: str
Expand Down

0 comments on commit 8453b10

Please sign in to comment.