From c9fba133ff1feaf6a6fae810301717a6e48677ae Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 25 May 2025 16:24:23 +0100 Subject: [PATCH 1/3] Remove PEP-604 methods from `Sentinel` on Python <3.10 We don't generally try to "backport PEP 604" on Python <3.10; this is more consistent with our features --- src/typing_extensions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/typing_extensions.py b/src/typing_extensions.py index 92e79def..8ad3c380 100644 --- a/src/typing_extensions.py +++ b/src/typing_extensions.py @@ -4244,11 +4244,12 @@ def __repr__(self): def __call__(self, *args, **kwargs): raise TypeError(f"{type(self).__name__!r} object is not callable") - def __or__(self, other): - return typing.Union[self, other] - - def __ror__(self, other): - return typing.Union[other, self] + if sys.version_info >= (3, 10): + def __or__(self, other): + return typing.Union[self, other] + + def __ror__(self, other): + return typing.Union[other, self] def __getstate__(self): raise TypeError(f"Cannot pickle {type(self).__name__!r} object") From b35fbf6566b2b457ffd1ec1b75810771cdc028e7 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 25 May 2025 16:25:44 +0100 Subject: [PATCH 2/3] Update src/typing_extensions.py --- src/typing_extensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typing_extensions.py b/src/typing_extensions.py index 8ad3c380..292641ae 100644 --- a/src/typing_extensions.py +++ b/src/typing_extensions.py @@ -4247,7 +4247,7 @@ def __call__(self, *args, **kwargs): if sys.version_info >= (3, 10): def __or__(self, other): return typing.Union[self, other] - + def __ror__(self, other): return typing.Union[other, self] From e18ea9f57d245a09a8d0710043330467fbdbd342 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 25 May 2025 16:34:39 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c13457e..b9c17184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# Unreleased + +- Remove `__or__` and `__ror__` methods from `typing_extensions.Sentinel` + on Python versions <3.10. PEP 604 was introduced in Python 3.10, and + `typing_extensions` does not generally attempt to backport PEP-604 methods + to prior versions. + # Release 4.14.0rc1 (May 24, 2025) - Drop support for Python 3.8 (including PyPy-3.8). Patch by [Victorien Plot](https://github.com/Viicos).