From 5b0816e784aa652cbae94cd96467c02cb64aa238 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 16 May 2024 16:53:19 -0400 Subject: [PATCH] Fix stdlib stubtest after latest typing-extensions release (#11923) --- requirements-tests.txt | 2 +- stdlib/types.pyi | 7 +++++++ stdlib/typing.pyi | 7 +++++++ stdlib/typing_extensions.pyi | 26 ++++++++++++++++++-------- stdlib/warnings.pyi | 14 +++++++++++++- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 2f7b1bc17..7b5ceac8b 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -20,5 +20,5 @@ stubdefaulter==0.1.0 termcolor>=2.3 tomli==2.0.1 tomlkit==0.12.4 -typing_extensions>=4.9.0rc1 +typing_extensions>=4.12.0rc1 uv==0.1.27 diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 38940b434..ab28b99b1 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -58,6 +58,9 @@ if sys.version_info >= (3, 10): if sys.version_info >= (3, 12): __all__ += ["get_original_bases"] +if sys.version_info >= (3, 13): + __all__ += ["CapsuleType"] + # Note, all classes "defined" here require special handling. _T1 = TypeVar("_T1") @@ -607,3 +610,7 @@ if sys.version_info >= (3, 10): def __ror__(self, value: Any, /) -> UnionType: ... def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... + +if sys.version_info >= (3, 13): + @final + class CapsuleType: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index d047f1c87..ec408182d 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -128,6 +128,9 @@ if sys.version_info >= (3, 11): if sys.version_info >= (3, 12): __all__ += ["TypeAliasType", "override"] +if sys.version_info >= (3, 13): + __all__ += ["get_protocol_members", "is_protocol", "NoDefault"] + Any = object() def final(f: _T) -> _T: ... @@ -985,3 +988,7 @@ if sys.version_info >= (3, 12): if sys.version_info >= (3, 13): def is_protocol(tp: type, /) -> bool: ... def get_protocol_members(tp: type, /) -> frozenset[str]: ... + @final + class _NoDefaultType: ... + + NoDefault: _NoDefaultType diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 48a398ba4..4bb09c394 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -95,6 +95,7 @@ __all__ = [ "Coroutine", "AsyncGenerator", "AsyncContextManager", + "CapsuleType", "ChainMap", "ContextManager", "Counter", @@ -166,6 +167,7 @@ __all__ = [ "MutableMapping", "MutableSequence", "MutableSet", + "NoDefault", "Optional", "Pattern", "Reversible", @@ -452,13 +454,6 @@ class TypeVarTuple: def __init__(self, name: str, *, default: Any | None = None) -> None: ... def __iter__(self) -> Any: ... # Unpack[Self] -class deprecated: - message: LiteralString - category: type[Warning] | None - stacklevel: int - def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... - def __call__(self, arg: _T, /) -> _T: ... - if sys.version_info >= (3, 12): from collections.abc import Buffer as Buffer from types import get_original_bases as get_original_bases @@ -494,10 +489,25 @@ else: def __buffer__(self, flags: int, /) -> memoryview: ... if sys.version_info >= (3, 13): - from typing import get_protocol_members as get_protocol_members, is_protocol as is_protocol + from types import CapsuleType as CapsuleType + from typing import NoDefault as NoDefault, get_protocol_members as get_protocol_members, is_protocol as is_protocol + from warnings import deprecated as deprecated else: def is_protocol(tp: type, /) -> bool: ... def get_protocol_members(tp: type, /) -> frozenset[str]: ... + @final + class _NoDefaultType: ... + + NoDefault: _NoDefaultType + @final + class CapsuleType: ... + + class deprecated: + message: LiteralString + category: type[Warning] | None + stacklevel: int + def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... + def __call__(self, arg: _T, /) -> _T: ... class Doc: documentation: str diff --git a/stdlib/warnings.pyi b/stdlib/warnings.pyi index 12afea933..539a8f237 100644 --- a/stdlib/warnings.pyi +++ b/stdlib/warnings.pyi @@ -3,7 +3,7 @@ from _warnings import warn as warn, warn_explicit as warn_explicit from collections.abc import Sequence from types import ModuleType, TracebackType from typing import Any, Generic, Literal, TextIO, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import LiteralString, TypeAlias __all__ = [ "warn", @@ -16,6 +16,10 @@ __all__ = [ "catch_warnings", ] +if sys.version_info >= (3, 13): + __all__ += ["deprecated"] + +_T = TypeVar("_T") _W = TypeVar("_W", bound=list[WarningMessage] | None) _ActionKind: TypeAlias = Literal["default", "error", "ignore", "always", "module", "once"] @@ -110,3 +114,11 @@ class catch_warnings(Generic[_W]): def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... + +if sys.version_info >= (3, 13): + class deprecated: + message: LiteralString + category: type[Warning] | None + stacklevel: int + def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... + def __call__(self, arg: _T, /) -> _T: ...