From 4b04967178cb64ff0376a196ac4e011b702380d2 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Tue, 21 Jun 2022 12:28:10 +1000 Subject: [PATCH 1/4] typing.AwaitableGenerator: add `type_check_only` --- stdlib/typing.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 969e61952d5f..a152037151f4 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -1,3 +1,5 @@ +from typing import type_check_only + import collections # Needed by aliases like DefaultDict, see mypy issue 2986 import sys from _typeshed import IdentityFunction, ReadableBuffer, Self as TypeshedSelf, SupportsKeysAndGetItem @@ -391,6 +393,7 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): # NOTE: This type does not exist in typing.py or PEP 484 but mypy needs it to exist. # The parameters correspond to Generator, but the 4th is the original type. +@type_check_only class AwaitableGenerator( Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta ): ... From 8198a29531cfe58d0a4661b071cd75cb391133d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jun 2022 02:39:25 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/typing.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index a152037151f4..31f1220d0e8b 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -1,10 +1,9 @@ -from typing import type_check_only - import collections # Needed by aliases like DefaultDict, see mypy issue 2986 import sys from _typeshed import IdentityFunction, ReadableBuffer, Self as TypeshedSelf, SupportsKeysAndGetItem from abc import ABCMeta, abstractmethod from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType +from typing import type_check_only from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final if sys.version_info >= (3, 7): From bbc7e5baa024f661bcf0b791060421982492a1d4 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Tue, 21 Jun 2022 13:23:40 +1000 Subject: [PATCH 3/4] typing.AwaitableGenerator: add `type_check_only` --- stdlib/typing.pyi | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 31f1220d0e8b..72633a539083 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -3,7 +3,6 @@ import sys from _typeshed import IdentityFunction, ReadableBuffer, Self as TypeshedSelf, SupportsKeysAndGetItem from abc import ABCMeta, abstractmethod from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType -from typing import type_check_only from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final if sys.version_info >= (3, 7): @@ -116,6 +115,9 @@ if sys.version_info >= (3, 11): "reveal_type", ] +# This itself is only available during type checking +def type_check_only(func_or_cls: _F) -> _F: ... + Any = object() @_final @@ -392,7 +394,7 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): # NOTE: This type does not exist in typing.py or PEP 484 but mypy needs it to exist. # The parameters correspond to Generator, but the 4th is the original type. -@type_check_only +@type_check_only # class AwaitableGenerator( Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta ): ... @@ -917,9 +919,6 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def __or__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... def __ior__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... -# This itself is only available during type checking -def type_check_only(func_or_cls: _F) -> _F: ... - if sys.version_info >= (3, 7): @_final class ForwardRef: From fb6d03e0a1c5851f6b7b3ed18a733d9fe2186451 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Tue, 21 Jun 2022 13:51:35 +1000 Subject: [PATCH 4/4] typing.AwaitableGenerator: add `type_check_only` --- stdlib/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 72633a539083..acbce5cd3a5f 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -394,7 +394,7 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): # NOTE: This type does not exist in typing.py or PEP 484 but mypy needs it to exist. # The parameters correspond to Generator, but the 4th is the original type. -@type_check_only # +@type_check_only class AwaitableGenerator( Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta ): ...