diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 76226faf9e97..b697bbb6dee4 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -181,6 +181,12 @@ _collections_abc.AsyncGenerator.__anext__ _collections_abc.AsyncGenerator.aclose _collections_abc.AsyncIterator.__anext__ +# Pretend typing.ByteString is a Union, to better match its documented semantics. +# As a side effect, this changes the definition of collections.abc.ByteString, which is okay, +# because it's not an ABC that makes any sense and was deprecated in 3.12 +_collections_abc\.ByteString +typing\.ByteString + _collections_abc.Callable # Typing-related weirdness _collections_abc.Mapping.get # Adding None to the Union messed up mypy _collections_abc.Sequence.index # Supporting None in end is not mandatory diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index da7bc9537093..b7dc763c7248 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -155,19 +155,12 @@ tkinter.tix.TkVersion # <= 3.13 # ======= -# Pretend typing.ByteString is a Union, to better match its documented semantics. -# As a side effect, this changes the definition of collections.abc.ByteString, which is okay, -# because it's not an ABC that makes any sense and was deprecated in 3.12 -_collections_abc.ByteString - ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any _?hashlib.scrypt # Raises TypeError if salt, n, r or p are None importlib.abc.Traversable.open # Problematic protocol signature at runtime, see source code comments. -typing\.ByteString - # Will always raise. Not included to avoid type checkers inferring that # TypeAliasType instances are callable. typing_extensions.TypeAliasType.__call__ diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index bbbe6fa9ba9f..fe0b34206cf9 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -121,19 +121,12 @@ tkinter.tix.TkVersion # <= 3.13 # ======= -# Pretend typing.ByteString is a Union, to better match its documented semantics. -# As a side effect, this changes the definition of collections.abc.ByteString, which is okay, -# because it's not an ABC that makes any sense and was deprecated in 3.12 -_collections_abc.ByteString - ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any _?hashlib.scrypt # Raises TypeError if salt, n, r or p are None importlib.abc.Traversable.open # Problematic protocol signature at runtime, see source code comments. -typing\.ByteString - # Will always raise. Not included to avoid type checkers inferring that # TypeAliasType instances are callable. typing_extensions.TypeAliasType.__call__ diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 5bdc3878b66c..ef1c5d12bf4a 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -120,19 +120,12 @@ tkinter.tix.TkVersion # <= 3.13 # ======= -# Pretend typing.ByteString is a Union, to better match its documented semantics. -# As a side effect, this changes the definition of collections.abc.ByteString, which is okay, -# because it's not an ABC that makes any sense and was deprecated in 3.12 -_collections_abc.ByteString - ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any _?hashlib.scrypt # Raises TypeError if salt, n, r or p are None importlib.abc.Traversable.open # Problematic protocol signature at runtime, see source code comments. -typing\.ByteString - # Will always raise. Not included to avoid type checkers inferring that # TypeAliasType instances are callable. typing_extensions.TypeAliasType.__call__ diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 4eda246de84e..12553bf684ee 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -81,19 +81,12 @@ typing(_extensions)?\.IO\.writelines # <= 3.13 # ======= -# Pretend typing.ByteString is a Union, to better match its documented semantics. -# As a side effect, this changes the definition of collections.abc.ByteString, which is okay, -# because it's not an ABC that makes any sense and was deprecated in 3.12 -_collections_abc.ByteString - ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any _?hashlib.scrypt # Raises TypeError if salt, n, r or p are None importlib.abc.Traversable.open # Problematic protocol signature at runtime, see source code comments. -typing\.ByteString - # Will always raise. Not included to avoid type checkers inferring that # TypeAliasType instances are callable. typing_extensions.TypeAliasType.__call__ diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index f706ee5c19ee..fb530e297148 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -18,7 +18,7 @@ collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in th collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 -collections.ByteString # see comments in py3_common.txt +collections.ByteString # see comments in common.txt collections.Callable collections.Mapping.get # Adding None to the Union messed up mypy collections.Sequence.index # Supporting None in end is not mandatory @@ -104,19 +104,12 @@ tkinter.tix.TkVersion # <= 3.13 # ======= -# Pretend typing.ByteString is a Union, to better match its documented semantics. -# As a side effect, this changes the definition of collections.abc.ByteString, which is okay, -# because it's not an ABC that makes any sense and was deprecated in 3.12 -_collections_abc.ByteString - ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any _?hashlib.scrypt # Raises TypeError if salt, n, r or p are None importlib.abc.Traversable.open # Problematic protocol signature at runtime, see source code comments. -typing\.ByteString - # Will always raise. Not included to avoid type checkers inferring that # TypeAliasType instances are callable. typing_extensions.TypeAliasType.__call__ diff --git a/stdlib/_collections_abc.pyi b/stdlib/_collections_abc.pyi index c63606a13ca9..319577c9284b 100644 --- a/stdlib/_collections_abc.pyi +++ b/stdlib/_collections_abc.pyi @@ -1,12 +1,13 @@ import sys from abc import abstractmethod from types import MappingProxyType -from typing import ( # noqa: Y022,Y038,UP035 +from typing import ( # noqa: Y022,Y038,UP035,Y057 AbstractSet as Set, AsyncGenerator as AsyncGenerator, AsyncIterable as AsyncIterable, AsyncIterator as AsyncIterator, Awaitable as Awaitable, + ByteString as ByteString, Callable as Callable, ClassVar, Collection as Collection, @@ -59,12 +60,8 @@ __all__ = [ "ValuesView", "Sequence", "MutableSequence", + "ByteString", ] -if sys.version_info < (3, 14): - from typing import ByteString as ByteString # noqa: Y057,UP035 - - __all__ += ["ByteString"] - if sys.version_info >= (3, 12): __all__ += ["Buffer"] diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 15a5864613d1..7a683a953b46 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -41,6 +41,7 @@ __all__ = [ "AsyncIterator", "Awaitable", "BinaryIO", + "ByteString", "Callable", "ChainMap", "ClassVar", @@ -109,9 +110,6 @@ __all__ = [ "runtime_checkable", ] -if sys.version_info < (3, 14): - __all__ += ["ByteString"] - if sys.version_info >= (3, 14): __all__ += ["evaluate_forward_ref"] @@ -923,8 +921,7 @@ class TextIO(IO[str]): @abstractmethod def __enter__(self) -> TextIO: ... -if sys.version_info < (3, 14): - ByteString: typing_extensions.TypeAlias = bytes | bytearray | memoryview +ByteString: typing_extensions.TypeAlias = bytes | bytearray | memoryview # Functions