From 71a0787887a04d1c2cde3658995b05a7b464c861 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 8 Feb 2022 21:18:45 -0800 Subject: [PATCH 1/3] add new typing features --- stdlib/typing.pyi | 8 ++++++++ stdlib/typing_extensions.pyi | 26 ++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index b01435282fe1..d4ac77bb4353 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -66,6 +66,10 @@ if sys.version_info >= (3, 8): # TypedDict is a (non-subscriptable) special form. TypedDict: object +if sys.version_info >= (3, 11): + Self: _SpecialForm + Never: _SpecialForm + if sys.version_info < (3, 7): class GenericMeta(type): ... @@ -697,6 +701,10 @@ def cast(typ: str, val: Any) -> Any: ... @overload def cast(typ: object, val: Any) -> Any: ... +if sys.version_info >= (3, 11): + def reveal_type(__obj: _T) -> _T: ... + def assert_never(__arg: Never) -> Never: ... + # Type constructors class NamedTuple(tuple[Any, ...]): diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index a57bb629d238..ffcba52f1b88 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -53,9 +53,6 @@ def runtime_checkable(cls: _TC) -> _TC: ... # This alias for above is kept here for backwards compatibility. runtime = runtime_checkable Final: _SpecialForm -Self: _SpecialForm -Required: _SpecialForm -NotRequired: _SpecialForm def final(f: _F) -> _F: ... @@ -103,7 +100,7 @@ class SupportsIndex(Protocol, metaclass=abc.ABCMeta): @abc.abstractmethod def __index__(self) -> int: ... -# PEP 612 support for Python < 3.9 +# New things in 3.10 if sys.version_info >= (3, 10): from typing import ( Concatenate as Concatenate, @@ -137,3 +134,24 @@ else: TypeAlias: _SpecialForm TypeGuard: _SpecialForm def is_typeddict(tp: object) -> bool: ... + +# New things in 3.11 +if sys.version_info >= (3, 11): + from typing import Self as Self, Never as Never, reveal_type as reveal_type, assert_never as assert_never +else: + Self: _SpecialForm + Never: _SpecialForm + def reveal_type(__obj: _T) -> _T: ... + def assert_never(__arg: Never) -> Never: ... + +# Experimental (hopefully these will be in 3.11) +Required: _SpecialForm +NotRequired: _SpecialForm + +def dataclass_transform( + *, + eq_default: bool = ..., + order_default: bool = ..., + kw_only_default: bool = ..., + field_descriptors: tuple[type[Any] | Callable[..., Any], ...] = ..., +) -> Callable[[_T], _T]: ... From 69bca2f7ddc6b75145a76f51a0b08d497aa5fc55 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Feb 2022 05:23:13 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/typing_extensions.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index ffcba52f1b88..cf9384a27028 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -137,7 +137,7 @@ else: # New things in 3.11 if sys.version_info >= (3, 11): - from typing import Self as Self, Never as Never, reveal_type as reveal_type, assert_never as assert_never + from typing import Never as Never, Self as Self, assert_never as assert_never, reveal_type as reveal_type else: Self: _SpecialForm Never: _SpecialForm From 7668b2dcc4cc7ae74bc510caedad8bbe21c50cda Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 8 Feb 2022 21:23:26 -0800 Subject: [PATCH 3/3] CI fixes --- stdlib/typing.pyi | 2 +- stdlib/typing_extensions.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index d4ac77bb4353..d384da71b2f2 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -68,7 +68,7 @@ if sys.version_info >= (3, 8): if sys.version_info >= (3, 11): Self: _SpecialForm - Never: _SpecialForm + Never: _SpecialForm = ... if sys.version_info < (3, 7): class GenericMeta(type): ... diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index cf9384a27028..180bdb5e6cef 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -142,7 +142,7 @@ else: Self: _SpecialForm Never: _SpecialForm def reveal_type(__obj: _T) -> _T: ... - def assert_never(__arg: Never) -> Never: ... + def assert_never(__arg: NoReturn) -> NoReturn: ... # Experimental (hopefully these will be in 3.11) Required: _SpecialForm