Skip to content
Merged
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Sentinel instances are callable.
typing_extensions.Sentinel.__call__


# =======
# <= 3.10
Expand Down
8 changes: 4 additions & 4 deletions stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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


# =============================================================
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Sentinel instances are callable.
typing_extensions.Sentinel.__call__


# =======
# <= 3.11
Expand Down
29 changes: 28 additions & 1 deletion stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ __all__ = [
"SupportsIndex",
"SupportsInt",
"SupportsRound",
"Reader",
"Writer",
# One-off things.
"Annotated",
"assert_never",
Expand All @@ -136,6 +138,7 @@ __all__ = [
"overload",
"override",
"Protocol",
"Sentinel",
"reveal_type",
"runtime",
"runtime_checkable",
Expand Down Expand Up @@ -199,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

Expand Down Expand Up @@ -446,6 +450,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 (
Expand Down Expand Up @@ -670,6 +687,16 @@ 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
class Sentinel:
def __init__(self, name: str, repr: str | None = None) -> None: ...
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