From 949ff116df56946ed11b91d9c6346e427b705b19 Mon Sep 17 00:00:00 2001 From: ChristianWitzler <57713653+ChristianWitzler@users.noreply.github.com> Date: Fri, 18 Nov 2022 11:45:08 +0100 Subject: [PATCH 1/2] Update code example in "Declaring decorators" - Added missing cast import - Changed revealed type --- docs/source/generics.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/generics.rst b/docs/source/generics.rst index 59d4aa1a2dea..40d2d9e6c45b 100644 --- a/docs/source/generics.rst +++ b/docs/source/generics.rst @@ -635,7 +635,7 @@ Before parameter specifications, here's how one might have annotated the decorat .. code-block:: python - from typing import Callable, TypeVar + from typing import Callable, TypeVar, cast F = TypeVar('F', bound=Callable[..., Any]) @@ -650,7 +650,7 @@ and that would enable the following type checks: .. code-block:: python - reveal_type(a) # str + reveal_type(a) # int add_forty_two('x') # Type check error: incompatible type "str"; expected "int" From 15c37dffd2b35584a4ec4f830742d85d2be57b12 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Fri, 18 Nov 2022 11:55:46 -0800 Subject: [PATCH 2/2] Apply suggestions from code review --- docs/source/generics.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/generics.rst b/docs/source/generics.rst index 40d2d9e6c45b..9a13e2a955c4 100644 --- a/docs/source/generics.rst +++ b/docs/source/generics.rst @@ -635,7 +635,7 @@ Before parameter specifications, here's how one might have annotated the decorat .. code-block:: python - from typing import Callable, TypeVar, cast + from typing import Any, Callable, TypeVar, cast F = TypeVar('F', bound=Callable[..., Any]) @@ -650,8 +650,8 @@ and that would enable the following type checks: .. code-block:: python - reveal_type(a) # int - add_forty_two('x') # Type check error: incompatible type "str"; expected "int" + reveal_type(a) # Revealed type is "builtins.int" + add_forty_two('x') # Argument 1 to "add_forty_two" has incompatible type "str"; expected "int" Note that the ``wrapper()`` function is not type-checked. Wrapper