From ddcf87670e1ea624bdef67e85dc548d88290b597 Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Mon, 29 Mar 2021 17:49:44 +0700 Subject: [PATCH 1/6] PEP 604: Add or operator to class type --- stdlib/builtins.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index ff2312727fae..edf8f1d3d4ac 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -156,6 +156,8 @@ class type(object): def __subclasscheck__(self, subclass: type) -> bool: ... @classmethod def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ... + if sys.version_info >= (3, 10): + def __or__(self, t: type) -> type: ... class super(object): @overload From 168045d3f63ebb271e3aa2783336551e33d3ae03 Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Tue, 30 Mar 2021 20:24:24 +0700 Subject: [PATCH 2/6] PEP 604: Replace parameter type by Any in or operator --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index edf8f1d3d4ac..6eeb7d8dad46 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -157,7 +157,7 @@ class type(object): @classmethod def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ... if sys.version_info >= (3, 10): - def __or__(self, t: type) -> type: ... + def __or__(self, t: Any) -> Any: ... class super(object): @overload From a884a45f8c5ab30a94e020e4b4887da65b2fbad5 Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Thu, 1 Apr 2021 10:40:01 +0700 Subject: [PATCH 3/6] PEP 604: Replace return type by types.Union --- stdlib/builtins.pyi | 4 +++- stdlib/types.pyi | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 6eeb7d8dad46..15abaf278653 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1,3 +1,5 @@ +import types + import sys from _typeshed import ( AnyPath, @@ -157,7 +159,7 @@ class type(object): @classmethod def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ... if sys.version_info >= (3, 10): - def __or__(self, t: Any) -> Any: ... + def __or__(self, t: Any) -> types.Union: ... class super(object): @overload diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 22ec7e5aae63..12007db9f8f6 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -334,3 +334,6 @@ if sys.version_info >= (3, 10): from builtins import _NotImplementedType NotImplementedType = _NotImplementedType # noqa F811 from builtins + + class Union: + __args__: Tuple[Any, ...] From de7dcbcce49c513dbb61a534a18d27a996013449 Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Thu, 1 Apr 2021 10:51:42 +0700 Subject: [PATCH 4/6] PEP 604: Fix formatting --- stdlib/builtins.pyi | 3 +-- stdlib/types.pyi | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 15abaf278653..78b29c5aa7e7 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1,6 +1,5 @@ -import types - import sys +import types from _typeshed import ( AnyPath, OpenBinaryMode, diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 12007db9f8f6..e037a3d08998 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -334,6 +334,5 @@ if sys.version_info >= (3, 10): from builtins import _NotImplementedType NotImplementedType = _NotImplementedType # noqa F811 from builtins - class Union: __args__: Tuple[Any, ...] From e4884bd86ad82c17456e03e982b8c226a9628e07 Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Thu, 1 Apr 2021 10:57:35 +0700 Subject: [PATCH 5/6] PEP 604: Replace Union by typing.Union in types.pyi --- stdlib/types.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index e037a3d08998..0fe34cf8327b 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -1,4 +1,5 @@ import sys +import typing from typing import ( Any, Awaitable, @@ -12,7 +13,6 @@ from typing import ( Tuple, Type, TypeVar, - Union, overload, ) from typing_extensions import Literal, final @@ -160,7 +160,7 @@ class GeneratorType: def send(self, __arg: Any) -> Any: ... @overload def throw( - self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ... + self, __typ: Type[BaseException], __val: typing.Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ... ) -> Any: ... @overload def throw(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> Any: ... @@ -175,7 +175,7 @@ class AsyncGeneratorType(Generic[_T_co, _T_contra]): def asend(self, __val: _T_contra) -> Awaitable[_T_co]: ... @overload def athrow( - self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ... + self, __typ: Type[BaseException], __val: typing.Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ... ) -> Awaitable[_T_co]: ... @overload def athrow(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ... @@ -190,7 +190,7 @@ class CoroutineType: def send(self, __arg: Any) -> Any: ... @overload def throw( - self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ... + self, __typ: Type[BaseException], __val: typing.Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ... ) -> Any: ... @overload def throw(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> Any: ... @@ -220,7 +220,7 @@ class MethodType: def __call__(self, *args: Any, **kwargs: Any) -> Any: ... class BuiltinFunctionType: - __self__: Union[object, ModuleType] + __self__: typing.Union[object, ModuleType] __name__: str __qualname__: str def __call__(self, *args: Any, **kwargs: Any) -> Any: ... From 2daf8a680b3008434fb27b25fb453fefdcbf893e Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Thu, 1 Apr 2021 11:03:24 +0700 Subject: [PATCH 6/6] PEP 604: Reformat imports in types.pyi --- stdlib/types.pyi | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 0fe34cf8327b..a3c45eaf93d9 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -1,20 +1,6 @@ import sys import typing -from typing import ( - Any, - Awaitable, - Callable, - Dict, - Generic, - Iterable, - Iterator, - Mapping, - Optional, - Tuple, - Type, - TypeVar, - overload, -) +from typing import Any, Awaitable, Callable, Dict, Generic, Iterable, Iterator, Mapping, Optional, Tuple, Type, TypeVar, overload from typing_extensions import Literal, final # ModuleType is exported from this module, but for circular import