From 14d3ab7f02df603fd8729a1ea883be3bd00f24f0 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:01:58 +0200 Subject: [PATCH 01/14] Update typing_extensions to 4.14.0rc1 --- stdlib/typing_extensions.pyi | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 37f8e8ba6a4b..df754986dfc3 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -110,6 +110,8 @@ __all__ = [ "SupportsIndex", "SupportsInt", "SupportsRound", + "Reader", + "Writer", # One-off things. "Annotated", "assert_never", @@ -136,6 +138,7 @@ __all__ = [ "overload", "override", "Protocol", + "Sentinel", "reveal_type", "runtime", "runtime_checkable", @@ -446,6 +449,19 @@ else: @abc.abstractmethod def __round__(self, ndigits: int, /) -> _T_co: ... +if sys.version_info >= (3, 14): + from io import Reader as Reader, Writer as Writer +else: + @runtime_checkable + class Reader(Protocol_[T_co]): + @abc.abstractmethod + def read(self, size: int = ..., /) -> T_co: ... + + @runtime_checkable + class Writer(Protocol[_T_contra]): + @abc.abstractmethod + def write(self, data: T_contra, /) -> int: ... + if sys.version_info >= (3, 13): from types import CapsuleType as CapsuleType from typing import ( @@ -670,6 +686,9 @@ else: globals: Mapping[str, Any] | None = None, # value types depend on the key locals: Mapping[str, Any] | None = None, # value types depend on the key type_params: Iterable[TypeVar | ParamSpec | TypeVarTuple] | None = None, - format: Format = Format.VALUE, # noqa: Y011 + format: Format | None = None, _recursive_guard: Container[str] = ..., ) -> AnnotationForm: ... + +# PEP 661 +Sentinel: _SpecialForm From e7f3c7ba2d0b31121946d2297de03347ced73cfc Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:02:26 +0200 Subject: [PATCH 02/14] Update typing_extensions --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 1c0d6147c4ff..811c4f7747e1 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -23,7 +23,7 @@ stubdefaulter==0.1.0; python_version < "3.14" termcolor>=2.3 tomli==2.2.1 tomlkit==0.13.2 -typing_extensions>=4.13.0rc1 +typing_extensions>=4.14.0rc1 uv==0.7.4 # Utilities for typeshed infrastructure scripts. From c39b224e5b84b9b7adc481e8547bee3e436180e9 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:05:39 +0200 Subject: [PATCH 03/14] Fixes --- stdlib/typing_extensions.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index df754986dfc3..47f133ebf828 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -202,6 +202,7 @@ _T = _TypeVar("_T") _F = _TypeVar("_F", bound=Callable[..., Any]) _TC = _TypeVar("_TC", bound=type[object]) _T_co = _TypeVar("_T_co", covariant=True) # Any type covariant containers. +_T_contra = _TypeVar("_T_contra", contravariant=True) class _Final: ... # This should be imported from typing but that breaks pytype @@ -453,14 +454,14 @@ if sys.version_info >= (3, 14): from io import Reader as Reader, Writer as Writer else: @runtime_checkable - class Reader(Protocol_[T_co]): + class Reader(Protocol[_T_co]): @abc.abstractmethod - def read(self, size: int = ..., /) -> T_co: ... + def read(self, size: int = ..., /) -> _T_co: ... @runtime_checkable class Writer(Protocol[_T_contra]): @abc.abstractmethod - def write(self, data: T_contra, /) -> int: ... + def write(self, data: _T_contra, /) -> int: ... if sys.version_info >= (3, 13): from types import CapsuleType as CapsuleType From 7087d04a4ebe1021ecc60facb3e0b1dc28694411 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:10:22 +0200 Subject: [PATCH 04/14] Add Sentinel to allowlist --- stdlib/@tests/stubtest_allowlists/common.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index a036c227f118..de6342c8ed90 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -488,6 +488,7 @@ typing(_extensions)?\.Sized typing(_extensions)?\.ValuesView typing_extensions\.Final typing_extensions\.LiteralString +typing_extensions\.Sentinal # Typing-related weirdness typing._SpecialForm.__call__ From e7da3a6fa1c58a87645521e6cf04df891a613862 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:11:31 +0200 Subject: [PATCH 05/14] Remove Sentinel (also, I can't type) --- stdlib/@tests/stubtest_allowlists/common.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index de6342c8ed90..a036c227f118 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -488,7 +488,6 @@ typing(_extensions)?\.Sized typing(_extensions)?\.ValuesView typing_extensions\.Final typing_extensions\.LiteralString -typing_extensions\.Sentinal # Typing-related weirdness typing._SpecialForm.__call__ From dba2c53f180dbea627eacba078764d262e1aa03a Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:13:58 +0200 Subject: [PATCH 06/14] Type Sentinel properly --- stdlib/typing_extensions.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 47f133ebf828..f9e404ffaed2 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -692,4 +692,7 @@ else: ) -> AnnotationForm: ... # PEP 661 -Sentinel: _SpecialForm +class Sentinel: + def __init__(self, name: str, repr: str | None = None) -> None: ... + def __or__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions + def __ror__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions From 64f1fce67c93abc6b146791c56c51854a691dee2 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:17:15 +0200 Subject: [PATCH 07/14] Add allowlist entry --- stdlib/@tests/stubtest_allowlists/py39.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index 496eb7231453..4682fc8840cf 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -44,6 +44,10 @@ tempfile.SpooledTemporaryFile.writable tkinter.Tk.split # Exists at runtime, but missing from stubs +# Will always raise. Not included to avoid type checkers inferring that +# TypeAliasType instances are callable. +typing_extensions.Sentinel.__call__ + # ======= # <= 3.11 From a2127611dfb3e0b17ad337833f31c0c76e74e173 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:17:34 +0200 Subject: [PATCH 08/14] Allowlist entry --- stdlib/@tests/stubtest_allowlists/py310.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index cb686b140098..5cf9df57af34 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -77,6 +77,10 @@ importlib.metadata._meta.SimplePath.__truediv__ # Runtime definition of protoco builtins.float.__setformat__ # Internal method for CPython test suite typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs +# Will always raise. Not included to avoid type checkers inferring that +# TypeAliasType instances are callable. +typing_extensions.Sentinel.__call__ + # ======= # <= 3.10 From d2757a00f74d7fdcee5f84fbbec3e469b3b9bc6a Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:18:58 +0200 Subject: [PATCH 09/14] typo --- stdlib/@tests/stubtest_allowlists/py310.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index 5cf9df57af34..1cb422f3c9a5 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -78,7 +78,7 @@ builtins.float.__setformat__ # Internal method for CPython test suite typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs # Will always raise. Not included to avoid type checkers inferring that -# TypeAliasType instances are callable. +# Sentinel instances are callable. typing_extensions.Sentinel.__call__ From 0d99811669b6dee0a1b09a8cb244c7c8c3057970 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:19:12 +0200 Subject: [PATCH 10/14] Update stdlib/@tests/stubtest_allowlists/py39.txt Co-authored-by: Jelle Zijlstra --- stdlib/@tests/stubtest_allowlists/py39.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index 4682fc8840cf..571e2c76c894 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -45,7 +45,7 @@ tempfile.SpooledTemporaryFile.writable tkinter.Tk.split # Exists at runtime, but missing from stubs # Will always raise. Not included to avoid type checkers inferring that -# TypeAliasType instances are callable. +# Sentinel instances are callable. typing_extensions.Sentinel.__call__ From 30f155528f46408fb60bcc6f83300cee9ba081c2 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:24:15 +0200 Subject: [PATCH 11/14] Union type fix for Python 3.9 Let's see whether using `TypeAlias` in here works ... --- stdlib/typing_extensions.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index f9e404ffaed2..14f6b814b7b4 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -68,6 +68,9 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035 if sys.version_info >= (3, 10): from types import UnionType + _UnionType: TypeAlias = UnionType +else: + _UnionType: TypeAlias = Any # Please keep order the same as at runtime. __all__ = [ @@ -694,5 +697,5 @@ else: # PEP 661 class Sentinel: def __init__(self, name: str, repr: str | None = None) -> None: ... - def __or__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions - def __ror__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions + def __or__(self, other: Any) -> _UnionType: ... # other can be any type form legal for unions + def __ror__(self, other: Any) -> _UnionType: ... # other can be any type form legal for unions From c3df9f6f8677d9dbbaf874c66a36f1a00c0adfb7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 25 May 2025 15:25:57 +0000 Subject: [PATCH 12/14] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/typing_extensions.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 14f6b814b7b4..555faab7930b 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -68,9 +68,10 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035 if sys.version_info >= (3, 10): from types import UnionType - _UnionType: TypeAlias = UnionType + + _UnionType: TypeAlias = ... else: - _UnionType: TypeAlias = Any + _UnionType: TypeAlias = ... # Please keep order the same as at runtime. __all__ = [ From b7fdb0d23c0d3639ff70b02c588e8cf1fd08bc4e Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:27:17 +0200 Subject: [PATCH 13/14] Update 3.14 allowlist --- stdlib/@tests/stubtest_allowlists/py314.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index 9dce720929db..f634f09ae0fc 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -169,10 +169,10 @@ typing(_extensions)?\.IO\.writelines .*\.ForwardRef\.__stringifier_dict__ # These protocols use ABC hackery at runtime. -io.Reader.__class_getitem__ -io.Reader.read -io.Writer.__class_getitem__ -io.Writer.write +(io|typing_extensions)\.Reader\.__class_getitem__ +(io|typing_extensions)\.Reader\.read +(io|typing_extensions)\.Writer\.__class_getitem__ +(io|typing_extensions)\.Writer\.write # ============================================================= From 0292bfb6f77403a1db9162cf2caf63ddef146c42 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 25 May 2025 17:35:17 +0200 Subject: [PATCH 14/14] Return a SpecialForm on ancient Python versions --- stdlib/typing_extensions.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 555faab7930b..07cd57ebc18f 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -69,10 +69,6 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035 if sys.version_info >= (3, 10): from types import UnionType - _UnionType: TypeAlias = ... -else: - _UnionType: TypeAlias = ... - # Please keep order the same as at runtime. __all__ = [ # Super-special typing primitives. @@ -698,5 +694,9 @@ else: # PEP 661 class Sentinel: def __init__(self, name: str, repr: str | None = None) -> None: ... - def __or__(self, other: Any) -> _UnionType: ... # other can be any type form legal for unions - def __ror__(self, other: Any) -> _UnionType: ... # other can be any type form legal for unions + if sys.version_info >= (3, 14): + def __or__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions + def __ror__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions + else: + def __or__(self, other: Any) -> _SpecialForm: ... # other can be any type form legal for unions + def __ror__(self, other: Any) -> _SpecialForm: ... # other can be any type form legal for unions