Skip to content

Commit

Permalink
Update typing_extensions for 4.7.* (#10344)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Jul 22, 2023
1 parent 65cb373 commit f577c4c
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 70 deletions.
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
88 changes: 83 additions & 5 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,68 @@ 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,
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,
overload as overload,
type_check_only,
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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]: ...
16 changes: 8 additions & 8 deletions tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 40 additions & 40 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -383,52 +383,52 @@ 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
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

# https://github.com/python/mypy/issues/15302
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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f577c4c

Please sign in to comment.