From 8a391f2789912d5b3ef9628869be5cad0d4dde7d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 21 Jun 2023 08:47:03 -0700 Subject: [PATCH 1/9] Update typing_extensions --- stdlib/typing.pyi | 4 +++ stdlib/typing_extensions.pyi | 49 +++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 2c5f820ea365..d9f9c18b9a7d 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -952,3 +952,7 @@ if sys.version_info >= (3, 12): if sys.version_info >= (3, 10): def __or__(self, right: Any) -> _SpecialForm: ... def __ror__(self, left: Any) -> _SpecialForm: ... + +if sys.version_info >= (3, 13): + def is_protocol(__tp: type) -> bool: ... + def get_protocol_members(__tp: type) -> frozenset[str]: ... diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 93087a45a108..336d68c67e25 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -13,7 +13,7 @@ from typing import ( # noqa: Y022,Y039 AsyncIterable as AsyncIterable, AsyncIterator as AsyncIterator, Awaitable as Awaitable, - Callable, + Callable as Callable, ChainMap as ChainMap, ClassVar as ClassVar, ContextManager as ContextManager, @@ -21,9 +21,9 @@ from typing import ( # noqa: Y022,Y039 Counter as Counter, DefaultDict as DefaultDict, Deque as Deque, - Mapping, + Mapping as Mapping, NoReturn as NoReturn, - Sequence, + Sequence as Sequence, SupportsAbs as SupportsAbs, SupportsBytes as SupportsBytes, SupportsComplex as SupportsComplex, @@ -32,6 +32,43 @@ from typing import ( # noqa: Y022,Y039 SupportsRound as SupportsRound, Text as Text, Type as Type, + AbstractSet as AbstractSet, + AnyStr as AnyStr, + BinaryIO as BinaryIO, + Callable as Callable, + Collection as Collection, + Container as Container, + Dict as Dict, + ForwardRef as ForwardRef, + FrozenSet as FrozenSet, + Generator as Generator, + Generic as Generic, + Hashable as Hashable, + IO as IO, + ItemsView as ItemsView, + Iterable as Iterable, + Iterator as Iterator, + KeysView as KeysView, + List as List, + Mapping as Mapping, + MappingView as MappingView, + Match as Match, + MutableMapping as MutableMapping, + MutableSequence as MutableSequence, + MutableSet as MutableSet, + Optional as Optional, + Pattern as Pattern, + Reversible as Reversible, + Sequence as Sequence, + Set as Set, + Sized as Sized, + TextIO as TextIO, + Tuple as Tuple, + Union as Union, + ValuesView as ValuesView, + cast as cast, + no_type_check as no_type_check, + no_type_check_decorator as no_type_check_decorator, _Alias, overload as overload, type_check_only, @@ -403,3 +440,9 @@ else: # Not actually a Protocol at runtime; see # https://github.com/python/typeshed/issues/10224 for why we're defining it this way def __buffer__(self, __flags: int) -> memoryview: ... + +if sys.version_info >= (3, 13): + from typing import is_protocol as is_protocol, get_protocol_members as get_protocol_members +else: + def is_protocol(__tp: type) -> bool: ... + def get_protocol_members(__tp: type) -> frozenset[str]: ... From 9b07182734b9724bb29c8f496287cb72c70ad61f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Jun 2023 15:50:00 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/typing_extensions.pyi | 37 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 336d68c67e25..da462227d7a9 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -6,45 +6,33 @@ from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import IdentityFunction, Incomplete from collections.abc import Iterable from typing import ( # noqa: Y022,Y039 + IO as IO, TYPE_CHECKING as TYPE_CHECKING, + AbstractSet as AbstractSet, Any as Any, + AnyStr as AnyStr, AsyncContextManager as AsyncContextManager, AsyncGenerator as AsyncGenerator, AsyncIterable as AsyncIterable, AsyncIterator as AsyncIterator, Awaitable as Awaitable, + BinaryIO as BinaryIO, Callable as Callable, ChainMap as ChainMap, ClassVar as ClassVar, + Collection as Collection, + Container as Container, ContextManager as ContextManager, Coroutine as Coroutine, Counter as Counter, DefaultDict as DefaultDict, Deque as Deque, - Mapping as Mapping, - NoReturn as NoReturn, - Sequence as Sequence, - SupportsAbs as SupportsAbs, - SupportsBytes as SupportsBytes, - SupportsComplex as SupportsComplex, - SupportsFloat as SupportsFloat, - SupportsInt as SupportsInt, - SupportsRound as SupportsRound, - Text as Text, - Type as Type, - AbstractSet as AbstractSet, - AnyStr as AnyStr, - BinaryIO as BinaryIO, - Callable as Callable, - Collection as Collection, - Container as Container, Dict as Dict, ForwardRef as ForwardRef, FrozenSet as FrozenSet, Generator as Generator, Generic as Generic, Hashable as Hashable, - IO as IO, ItemsView as ItemsView, Iterable as Iterable, Iterator as Iterator, @@ -56,20 +44,29 @@ from typing import ( # noqa: Y022,Y039 MutableMapping as MutableMapping, MutableSequence as MutableSequence, MutableSet as MutableSet, + NoReturn as NoReturn, Optional as Optional, Pattern as Pattern, Reversible as Reversible, Sequence as Sequence, Set as Set, Sized as Sized, + SupportsAbs as SupportsAbs, + SupportsBytes as SupportsBytes, + SupportsComplex as SupportsComplex, + SupportsFloat as SupportsFloat, + SupportsInt as SupportsInt, + SupportsRound as SupportsRound, + Text as Text, TextIO as TextIO, Tuple as Tuple, + Type as Type, Union as Union, ValuesView as ValuesView, + _Alias, cast as cast, no_type_check as no_type_check, no_type_check_decorator as no_type_check_decorator, - _Alias, overload as overload, type_check_only, ) @@ -442,7 +439,7 @@ else: def __buffer__(self, __flags: int) -> memoryview: ... if sys.version_info >= (3, 13): - from typing import is_protocol as is_protocol, get_protocol_members as get_protocol_members + from typing import get_protocol_members as get_protocol_members, is_protocol as is_protocol else: def is_protocol(__tp: type) -> bool: ... def get_protocol_members(__tp: type) -> frozenset[str]: ... From 6b998b9223b0aa3751e2a99d5088280cbe1b54b3 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 21 Jun 2023 08:54:01 -0700 Subject: [PATCH 3/9] Install typing-extensions from git --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 8f9b673d725b..480ab4d45b78 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -21,7 +21,7 @@ stubdefaulter==0.1.0 termcolor>=2.3 tomli==2.0.1 tomlkit==0.11.8 -typing-extensions +typing_extensions @ git+https://github.com/python/typing_extensions.git # Type stubs used to type check our scripts. types-pyyaml>=6.0.12.7 From bc1c069dc803dd213da4fae8dee519e435b5b433 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 21 Jun 2023 18:26:57 -0700 Subject: [PATCH 4/9] Try to fix stubtest --- stdlib/typing_extensions.pyi | 1 + tests/stubtest_allowlists/py3_common.txt | 80 ++++++++++++------------ 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index da462227d7a9..99b5f95c24ff 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -143,6 +143,7 @@ __all__ = [ "get_original_bases", "get_overloads", "get_type_hints", + 'AbstractSet', 'AnyStr', 'BinaryIO', 'Callable', 'Collection', 'Container', 'Dict', 'ForwardRef', 'FrozenSet', 'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping', 'MutableSequence', 'MutableSet', 'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'TextIO', 'Tuple', 'Union', 'ValuesView', 'cast', 'get_protocol_members', 'is_protocol', 'no_type_check', 'no_type_check_decorator' ] _T = typing.TypeVar("_T") diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index d8d282839417..7120bc5e00b5 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -99,7 +99,7 @@ tkinter.tix.[A-Z_]+ tkinter.tix.TclVersion tkinter.tix.TkVersion traceback.TracebackException.from_exception # explicitly expanding arguments going into TracebackException __init__ -typing.IO.__next__ # Added because IO streams are iterable. See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 +typing(_extensions)?\.IO\.__next__ # Added because IO streams are iterable. See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 typing.type_check_only # typing decorator that is not available at runtime unittest.mock.patch # It's a complicated overload and I haven't been able to figure out why stubtest doesn't like it urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified @@ -383,8 +383,9 @@ tempfile._TemporaryFileWrapper.[\w_]+ # Dynamically specified by __getattr__, a typing_extensions\._SpecialForm.* typing_extensions\.TypeVar.* typing_extensions\.ParamSpec.* -typing\.Generic +typing(_extensions)?\.Generic typing\.Protocol +typing\._TypedDict\..* # Special primitives typing_extensions\.Annotated @@ -392,36 +393,33 @@ typing_extensions\.NamedTuple typing_extensions\.LiteralString typing_extensions\.Coroutine typing_extensions\.Awaitable -typing_extensions\.AsyncIterator -typing_extensions\.AsyncIterable -typing_extensions\.AsyncGenerator -typing\.ValuesView -typing\.Sized -typing\.Sequence -typing\.Reversible -typing\.Pattern -typing\.MutableSet -typing\.MutableSequence -typing\.MutableMapping -typing\.Match -typing\.MappingView -typing\.Mapping -typing\.KeysView -typing\.Iterator -typing\.Iterable -typing\.ItemsView -typing\.Hashable -typing\.Generator -typing\.Coroutine -typing\.Collection -typing\.Container +typing(_extensions)?\.AsyncIterator +typing(_extensions)?\.AsyncIterable +typing(_extensions)?\.AsyncGenerator +typing(_extensions)?\.ValuesView +typing(_extensions)?\.Sized +typing(_extensions)?\.Sequence +typing(_extensions)?\.Reversible +typing(_extensions)?\.Pattern +typing(_extensions)?\.MutableSet +typing(_extensions)?\.MutableSequence +typing(_extensions)?\.MutableMapping +typing(_extensions)?\.Match +typing(_extensions)?\.MappingView +typing(_extensions)?\.Mapping +typing(_extensions)?\.KeysView +typing(_extensions)?\.Iterator +typing(_extensions)?\.Iterable +typing(_extensions)?\.ItemsView +typing(_extensions)?\.Hashable +typing(_extensions)?\.Generator +typing(_extensions)?\.Coroutine +typing(_extensions)?\.Collection +typing(_extensions)?\.Container typing\.ByteString -typing\.AwaitableGenerator -typing\.Awaitable -typing\.AsyncIterator -typing\.AsyncIterable -typing\.AsyncGenerator -typing\.AbstractSet +typing(_extensions)?\.AwaitableGenerator +typing(_extensions)?\.Awaitable +typing(_extensions)?\.AbstractSet # Internal attributes .*\.__protocol_attrs__ @@ -433,6 +431,8 @@ typing_extensions.NewType.__mro_entries__ # just exists for an error message typing_extensions.NewType.__call__ typing_extensions\.deprecated typing_extensions\.override +typing_extensions\.get_protocol_members +typing_extensions\.is_protocol # Typing-related weirdness _collections_abc.Callable @@ -447,14 +447,14 @@ _collections_abc.ByteString # These are abstract properties at runtime, # but marking them as such in the stub breaks half the the typed-Python ecosystem (see #8726) -typing.IO.closed -typing.IO.mode -typing.IO.name -typing.TextIO.buffer -typing.TextIO.encoding -typing.TextIO.errors -typing.TextIO.line_buffering -typing.TextIO.newlines +typing(_extensions)?\.IO\.closed +typing(_extensions)?\.IO\.mode +typing(_extensions)?\.IO\.name +typing(_extensions)?\.TextIO\.buffer +typing(_extensions)?\.TextIO\.encoding +typing(_extensions)?\.TextIO\.errors +typing(_extensions)?\.TextIO\.line_buffering +typing(_extensions)?\.TextIO\.newlines types.MethodType.__closure__ # read-only but not actually a property; stubtest thinks it doesn't exist. types.MethodType.__defaults__ # read-only but not actually a property; stubtest thinks it doesn't exist. @@ -603,7 +603,7 @@ mmap.mmap.__iter__ mmap.mmap.__contains__ xml.etree.ElementTree.Element.__iter__ xml.etree.cElementTree.Element.__iter__ -typing.IO.__iter__ # See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 +typing(_extensions)?\.IO\.__iter__ # See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 # LC_MESSAGES is sometimes present in __all__, sometimes not, # so stubtest will sometimes complain about exported names being different at runtime to the exported names in the stub From 262d593111d08c566635ad1e3fd21f2d676cb8e4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 22 Jun 2023 01:28:33 +0000 Subject: [PATCH 5/9] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/typing_extensions.pyi | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 99b5f95c24ff..524790521c18 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -143,7 +143,45 @@ __all__ = [ "get_original_bases", "get_overloads", "get_type_hints", - 'AbstractSet', 'AnyStr', 'BinaryIO', 'Callable', 'Collection', 'Container', 'Dict', 'ForwardRef', 'FrozenSet', 'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping', 'MutableSequence', 'MutableSet', 'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'TextIO', 'Tuple', 'Union', 'ValuesView', 'cast', 'get_protocol_members', 'is_protocol', 'no_type_check', 'no_type_check_decorator' + "AbstractSet", + "AnyStr", + "BinaryIO", + "Callable", + "Collection", + "Container", + "Dict", + "ForwardRef", + "FrozenSet", + "Generator", + "Generic", + "Hashable", + "IO", + "ItemsView", + "Iterable", + "Iterator", + "KeysView", + "List", + "Mapping", + "MappingView", + "Match", + "MutableMapping", + "MutableSequence", + "MutableSet", + "Optional", + "Pattern", + "Reversible", + "Sequence", + "Set", + "Sized", + "TextIO", + "Tuple", + "Union", + "ValuesView", + "cast", + "get_protocol_members", + "is_protocol", + "no_type_check", + "no_type_check_decorator", ] _T = typing.TypeVar("_T") From 56c2fe010919cfd6b2e56be013588817ff871843 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 21 Jun 2023 18:33:24 -0700 Subject: [PATCH 6/9] fix --- tests/stubtest_allowlists/py3_common.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 7120bc5e00b5..19541af8e92d 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -385,7 +385,7 @@ typing_extensions\.TypeVar.* typing_extensions\.ParamSpec.* typing(_extensions)?\.Generic typing\.Protocol -typing\._TypedDict\..* +typing_extensions\._TypedDict\..* # Special primitives typing_extensions\.Annotated From 2723340456024773515fb7a8d785871cac869f1e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 21 Jun 2023 18:39:37 -0700 Subject: [PATCH 7/9] Fix 3.10+ --- tests/stubtest_allowlists/py310.txt | 16 ++++++++-------- tests/stubtest_allowlists/py311.txt | 16 ++++++++-------- tests/stubtest_allowlists/py312.txt | 16 ++++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index bb38e5691b8b..fb8170366c23 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -118,14 +118,14 @@ _collections_abc.MutableMapping.setdefault # typing.IO uses positional-or-keyword arguments, but in the stubs we prefer # to mark these as positional-only for compatibility with existing sub-classes. -typing.BinaryIO.write -typing.IO.read -typing.IO.readline -typing.IO.readlines -typing.IO.seek -typing.IO.truncate -typing.IO.write -typing.IO.writelines +typing(_extensions)?\.BinaryIO\.write +typing(_extensions)?\.IO\.read +typing(_extensions)?\.IO\.readline +typing(_extensions)?\.IO\.readlines +typing(_extensions)?\.IO\.seek +typing(_extensions)?\.IO\.truncate +typing(_extensions)?\.IO\.write +typing(_extensions)?\.IO\.writelines # positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib _collections_abc.Coroutine.send diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index d6e1754b1c4e..9f9212f2d060 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -48,14 +48,14 @@ _collections_abc.MutableMapping.setdefault # typing.IO uses positional-or-keyword arguments, but in the stubs we prefer # to mark these as positional-only for compatibility with existing sub-classes. -typing.BinaryIO.write -typing.IO.read -typing.IO.readline -typing.IO.readlines -typing.IO.seek -typing.IO.truncate -typing.IO.write -typing.IO.writelines +typing(_extensions)?\.BinaryIO\.write +typing(_extensions)?\.IO\.read +typing(_extensions)?\.IO\.readline +typing(_extensions)?\.IO\.readlines +typing(_extensions)?\.IO\.seek +typing(_extensions)?\.IO\.truncate +typing(_extensions)?\.IO\.write +typing(_extensions)?\.IO\.writelines # positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib _collections_abc.Coroutine.send diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index e01e45d104ff..685f8c5dd03b 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -220,14 +220,14 @@ _collections_abc.MutableMapping.setdefault # typing.IO uses positional-or-keyword arguments, but in the stubs we prefer # to mark these as positional-only for compatibility with existing sub-classes. -typing.BinaryIO.write -typing.IO.read -typing.IO.readline -typing.IO.readlines -typing.IO.seek -typing.IO.truncate -typing.IO.write -typing.IO.writelines +typing(_extensions)?\.BinaryIO\.write +typing(_extensions)?\.IO\.read +typing(_extensions)?\.IO\.readline +typing(_extensions)?\.IO\.readlines +typing(_extensions)?\.IO\.seek +typing(_extensions)?\.IO\.truncate +typing(_extensions)?\.IO\.write +typing(_extensions)?\.IO\.writelines # positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib _collections_abc.Coroutine.send From 3afc7d0e1a785005f541e0ee16b39a5f0e8767e1 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 21 Jun 2023 18:44:02 -0700 Subject: [PATCH 8/9] fix flake8 --- stdlib/typing_extensions.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 524790521c18..3169dd305004 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -4,8 +4,7 @@ import sys import typing from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import IdentityFunction, Incomplete -from collections.abc import Iterable -from typing import ( # noqa: Y022,Y039 +from typing import ( # noqa: Y022,Y037,Y038,Y039 IO as IO, TYPE_CHECKING as TYPE_CHECKING, AbstractSet as AbstractSet, From 8094faf9f5ca8a8e8596372d564f72bd6aea6100 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 22 Jul 2023 12:25:16 +0100 Subject: [PATCH 9/9] don't install from git --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 4044195ae8c6..e90de87ddfbf 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -21,7 +21,7 @@ stubdefaulter==0.1.0 termcolor>=2.3 tomli==2.0.1 tomlkit==0.11.8 -typing_extensions @ git+https://github.com/python/typing_extensions.git +typing_extensions # Type stubs used to type check our scripts. types-pyyaml>=6.0.12.7