Skip to content

Commit

Permalink
A few typo fixes (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
fofoni authored May 24, 2024
1 parent 2e70529 commit 75d0d30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions docs/source/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ For class methods, you can also define generic ``cls``, using :py:class:`type`:

.. code-block:: python
from typing import TypeVar, Type
from typing import Optional, TypeVar, Type
T = TypeVar('T', bound='Friend')
class Friend:
other: "Friend" = None
other: Optional["Friend"] = None
@classmethod
def make_pair(cls: Type[T]) -> tuple[T, T]:
def make_pair(cls: type[T]) -> tuple[T, T]:
a, b = cls(), cls()
a.other = b
b.other = a
Expand Down Expand Up @@ -674,19 +674,19 @@ alter the signature of the input function:
P = ParamSpec('P')
T = TypeVar('T')
# We reuse 'P' in the return type, but replace 'T' with 'str'
# We reuse 'P' in the return type, but replace 'T' with 'str'
def stringify(func: Callable[P, T]) -> Callable[P, str]:
def wrapper(*args: P.args, **kwds: P.kwargs) -> str:
return str(func(*args, **kwds))
return wrapper
@stringify
def add_forty_two(value: int) -> int:
return value + 42
@stringify
def add_forty_two(value: int) -> int:
return value + 42
a = add_forty_two(3)
reveal_type(a) # Revealed type is "builtins.str"
add_forty_two('x') # error: Argument 1 to "add_forty_two" has incompatible type "str"; expected "int"
a = add_forty_two(3)
reveal_type(a) # Revealed type is "builtins.str"
add_forty_two('x') # error: Argument 1 to "add_forty_two" has incompatible type "str"; expected "int"
Or insert an argument:

Expand Down
6 changes: 3 additions & 3 deletions docs/source/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ encouraged to use some of the new type-friendly classes.
NamedTuple (described in :pep:`484`) is preferred over
namedtuple.

Data classes (described in :pep:`557`) is preferred over
Data classes (described in :pep:`557`) are preferred over
untyped dictionaries.

TypedDict (described in :pep:`589`) is preferred over
Expand Down Expand Up @@ -647,8 +647,8 @@ Python 3.6 introduced support for variable type annotations, as
specified in :pep:`526`.

If you need to support older versions of Python, type annotations can
still be provided as “type comments”. These comments take the form #
type: .
still be provided as “type comments”. These comments take the form
``# type:``.

.. code:: python
Expand Down

0 comments on commit 75d0d30

Please sign in to comment.