From 75d0d30eee04e508941ad2c0926fc0cbd0a282b9 Mon Sep 17 00:00:00 2001 From: Pedro Fonini Date: Fri, 24 May 2024 10:34:17 -0300 Subject: [PATCH] A few typo fixes (#1750) --- docs/source/generics.rst | 20 ++++++++++---------- docs/source/libraries.rst | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/source/generics.rst b/docs/source/generics.rst index 5cada315d..120124566 100644 --- a/docs/source/generics.rst +++ b/docs/source/generics.rst @@ -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 @@ -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: diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 1f4f87dec..376811ad0 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -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 @@ -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