From f577c4c133ae6bb57cade534179b41ef04b5731f Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 22 Jul 2023 03:51:22 -0800 Subject: [PATCH] Update typing_extensions for 4.7.* (#10344) --- requirements-tests.txt | 2 +- stdlib/typing.pyi | 4 ++ stdlib/typing_extensions.pyi | 88 ++++++++++++++++++++++-- tests/stubtest_allowlists/py310.txt | 16 ++--- tests/stubtest_allowlists/py311.txt | 16 ++--- tests/stubtest_allowlists/py312.txt | 16 ++--- tests/stubtest_allowlists/py3_common.txt | 80 ++++++++++----------- 7 files changed, 152 insertions(+), 70 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 8059d4e28..ba70abe09 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==4.6.3 +typing_extensions # Type stubs used to type check our scripts. types-pyyaml>=6.0.12.7 diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 6c37f3222..81cf3817f 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -956,3 +956,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 aa55d29b1..efcc13e42 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -4,26 +4,52 @@ 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, Any as Any, + AnyStr as AnyStr, AsyncContextManager as AsyncContextManager, AsyncGenerator as AsyncGenerator, AsyncIterable as AsyncIterable, AsyncIterator as AsyncIterator, Awaitable as Awaitable, - Callable, + 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, + Dict as Dict, + ForwardRef as ForwardRef, + FrozenSet as FrozenSet, + Generator as Generator, + Generic as Generic, + Hashable as Hashable, + 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, NoReturn as NoReturn, - Sequence, + 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, @@ -31,8 +57,15 @@ from typing import ( # noqa: Y022,Y039 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, overload as overload, type_check_only, ) @@ -109,6 +142,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", ] _T = typing.TypeVar("_T") @@ -403,3 +475,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 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]: ... diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index bb38e5691..fb8170366 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 3b7809429..dfcbed1f1 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -50,14 +50,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 9d3063e69..15e16684b 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -163,14 +163,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/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 1956427a5..c38a3b94e 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_extensions\._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 typing_extensions.NewType.__mro_entries__ # just exists for an error message @@ -429,6 +427,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 @@ -443,14 +443,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. @@ -599,7 +599,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