Skip to content

Commit 8e6a886

Browse files
authored
Update typing_extensions to >=4.16.0rc1 (#15934)
* `typing_extensions`: re-export `builtins.sentinel` on Python 3.15+ This would make ty's implementation of `builtins.sentinel` a little easier * Update typing_extensions.pyi * Update typing_extensions version to 4.16.0rc1 * Update typing_extensions.pyi * allow * a surprise, to be sure, but a welcome one * Update stdlib/typing_extensions.pyi * harmonize builtins and typing_extensions, fix various `__(r)or__` methods * Apply suggestions from code review
1 parent 289e5d3 commit 8e6a886

10 files changed

Lines changed: 59 additions & 29 deletions

File tree

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ stubdefaulter==0.1.0; python_version < "3.15"
1717
termcolor>=2.3
1818
tomli==2.4.1; python_version < "3.11"
1919
tomlkit==0.14.0
20-
typing_extensions>=4.15.0rc1
20+
typing_extensions>=4.16.0rc1
2121
uv==0.11.15
2222

2323
# Utilities for typeshed infrastructure scripts.

stdlib/@tests/stubtest_allowlists/py310.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ typing_extensions.NewType.__mro_entries__
2929
importlib.metadata._meta.SimplePath.__truediv__ # Runtime definition of protocol is incorrect
3030

3131

32-
# ===================================
33-
# Pre-existing errors from Python 3.9
34-
# ===================================
35-
36-
3732
# =======
3833
# <= 3.10
3934
# =======
@@ -56,9 +51,10 @@ tkinter.Tk.split # Exists at runtime, but missing from stubs
5651
typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs
5752

5853
typing_extensions.LiteralString
54+
5955
# Will always raise. Not included to avoid type checkers inferring that
6056
# Sentinel instances are callable.
61-
typing_extensions.Sentinel.__call__
57+
typing_extensions.sentinel.__call__
6258

6359

6460
# =======
@@ -141,6 +137,11 @@ tkinter.simpledialog.[A-Z_]+
141137
tkinter.simpledialog.TclVersion
142138
tkinter.simpledialog.TkVersion
143139

140+
# The runtime does some hacks to deprecate passing various parameters
141+
# positionally or by keyword. We just present a signature in the stub
142+
# that describes the way users are supposed to call the constructor.
143+
typing_extensions.sentinel.__init__
144+
144145

145146
# =============================================================
146147
# Allowlist entries that cannot or should not be fixed; <3.15

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ tkinter.simpledialog.[A-Z_]+
115115
tkinter.simpledialog.TclVersion
116116
tkinter.simpledialog.TkVersion
117117

118+
# The runtime does some hacks to deprecate passing various parameters
119+
# positionally or by keyword. We just present a signature in the stub
120+
# that describes the way users are supposed to call the constructor.
121+
typing_extensions.sentinel.__init__
122+
118123

119124
# =============================================================
120125
# Allowlist entries that cannot or should not be fixed; <3.15

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ tkinter.simpledialog.[A-Z_]+
108108
tkinter.simpledialog.TclVersion
109109
tkinter.simpledialog.TkVersion
110110

111+
# The runtime does some hacks to deprecate passing various parameters
112+
# positionally or by keyword. We just present a signature in the stub
113+
# that describes the way users are supposed to call the constructor.
114+
typing_extensions.sentinel.__init__
115+
111116

112117
# =============================================================
113118
# Allowlist entries that cannot or should not be fixed; <3.15

stdlib/@tests/stubtest_allowlists/py313.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ tkinter.simpledialog.[A-Z_]+
6161
tkinter.simpledialog.TclVersion
6262
tkinter.simpledialog.TkVersion
6363

64+
# The runtime does some hacks to deprecate passing various parameters
65+
# positionally or by keyword. We just present a signature in the stub
66+
# that describes the way users are supposed to call the constructor.
67+
typing_extensions.sentinel.__init__
68+
6469

6570
# =============================================================
6671
# Allowlist entries that cannot or should not be fixed; <3.15
@@ -108,9 +113,6 @@ multiprocessing.managers._BaseDictProxy.values
108113
# To match `dict`, we lie about the runtime, but use overloads to match the correct behavior
109114
types.MappingProxyType.get
110115

111-
typing_extensions.Protocol # Super-special typing primitive
112-
113-
114116
# =============================================================
115117
# Allowlist entries that cannot or should not be fixed; >= 3.12
116118
# =============================================================

stdlib/@tests/stubtest_allowlists/py314.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ tkinter.simpledialog.[A-Z_]+
6161
tkinter.simpledialog.TclVersion
6262
tkinter.simpledialog.TkVersion
6363

64+
# The runtime does some hacks to deprecate passing various parameters
65+
# positionally or by keyword. We just present a signature in the stub
66+
# that describes the way users are supposed to call the constructor.
67+
typing_extensions.sentinel.__init__
68+
6469

6570
# =============================================================
6671
# Allowlist entries that cannot or should not be fixed; <3.15

stdlib/@tests/stubtest_allowlists/py315.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ base64.b64decode
4646
urllib.parse.urlunparse
4747
urllib.parse.urlunsplit
4848

49-
# Runtime __all__ includes no_type_check_decorator, but the attribute does not exist on Python 3.15.
50-
typing_extensions.__all__
51-
5249
# Internal implementation details of the sampling profiler.
5350
profiling.sampling.binary_collector
5451
profiling.sampling.binary_reader

stdlib/builtins.pyi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ from _typeshed import (
3333
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
3434
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
3535
from os import PathLike
36-
from types import CellType, CodeType, EllipsisType, GenericAlias, NotImplementedType, TracebackType
36+
from types import CellType, CodeType, EllipsisType, GenericAlias, NotImplementedType, TracebackType, UnionType
3737

3838
# mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping}
3939
# are imported from collections.abc in builtins.pyi
@@ -2185,11 +2185,13 @@ if sys.version_info >= (3, 15):
21852185
class sentinel:
21862186
__name__: str
21872187
__module__: str
2188-
def __new__(cls, name: str, /, *, repr: str | None = None) -> Self: ...
2189-
def __copy__(self, /) -> Self: ...
2190-
def __deepcopy__(self, memo: Any, /) -> Self: ...
2191-
def __or__(self, other: Any, /) -> Any: ...
2192-
def __ror__(self, other: Any, /) -> Any: ...
2188+
def __new__(cls, name: str, /, *, repr: str | None = None) -> sentinel: ...
2189+
def __copy__(self, /) -> sentinel: ...
2190+
def __deepcopy__(self, memo: Any, /) -> sentinel: ...
2191+
# `other` can be any legal form for unions.
2192+
# `x | x` creates a `sentinel` instance if `x` is a sentinel, not a `UnionType` instance.
2193+
def __or__(self, other: Any, /) -> UnionType | sentinel: ...
2194+
def __ror__(self, other: Any, /) -> UnionType | sentinel: ...
21932195

21942196
@overload
21952197
def sorted(

stdlib/types.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,10 @@ class GenericAlias:
703703
@property
704704
def __typing_unpacked_tuple_args__(self) -> tuple[Any, ...] | None: ...
705705

706-
def __or__(self, value: Any, /) -> UnionType: ...
707-
def __ror__(self, value: Any, /) -> UnionType: ...
706+
# `other` can be any legal form for unions.
707+
# `list[int] | list[int]` creates a `GenericAlias` instance, not a `UnionType` instance
708+
def __or__(self, value: Any, /) -> UnionType | GenericAlias: ...
709+
def __ror__(self, value: Any, /) -> UnionType | GenericAlias: ...
708710

709711
# GenericAlias delegates attr access to `__origin__`
710712
def __getattr__(self, name: str) -> Any: ...

stdlib/typing_extensions.pyi

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ __all__ = [
143143
"override",
144144
"Protocol",
145145
"Sentinel",
146+
"sentinel",
146147
"reveal_type",
147148
"runtime",
148149
"runtime_checkable",
@@ -680,11 +681,21 @@ else:
680681
def type_repr(value: object) -> str: ...
681682

682683
# PEP 661
683-
class Sentinel:
684-
def __init__(self, name: str, repr: str | None = None) -> None: ...
685-
if sys.version_info >= (3, 14):
686-
def __or__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions
687-
def __ror__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions
688-
else:
689-
def __or__(self, other: Any) -> _SpecialForm: ... # other can be any type form legal for unions
690-
def __ror__(self, other: Any) -> _SpecialForm: ... # other can be any type form legal for unions
684+
if sys.version_info >= (3, 15):
685+
from builtins import sentinel as sentinel
686+
else:
687+
class sentinel:
688+
def __init__(self, name: str, /, *, repr: str | None = None) -> None: ...
689+
__name__: str
690+
__module__: str
691+
if sys.version_info >= (3, 14):
692+
# `other`` can be any type form legal for unions.
693+
# `x | x` creates a `sentinel` instance if `x` is a sentinel, not a `UnionType` instance
694+
def __or__(self, other: Any) -> UnionType | sentinel: ...
695+
def __ror__(self, other: Any) -> UnionType | sentinel: ...
696+
else:
697+
# other can be any type form legal for unions
698+
def __or__(self, other: Any) -> _SpecialForm: ...
699+
def __ror__(self, other: Any) -> _SpecialForm: ...
700+
701+
Sentinel = sentinel

0 commit comments

Comments
 (0)