From c7ec2158ea81579e523169def13788eb3dccf8a4 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Sat, 29 Mar 2025 18:39:40 +0100 Subject: [PATCH] Update `typing.Union` and `types.UnionType` definitions for 3.14 --- stdlib/types.pyi | 27 +++++++++++++++------------ stdlib/typing.pyi | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 542979d4afc5..15afd6838a05 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -17,7 +17,7 @@ from collections.abc import ( from importlib.machinery import ModuleSpec # pytype crashes if types.MappingProxyType inherits from collections.abc.Mapping instead of typing.Mapping -from typing import Any, ClassVar, Literal, Mapping, TypeVar, final, overload # noqa: Y022 +from typing import Any, ClassVar, Literal, Mapping, TypeVar, Union, final, overload # noqa: Y022 from typing_extensions import ParamSpec, Self, TypeAliasType, TypeVarTuple, deprecated __all__ = [ @@ -672,17 +672,9 @@ if sys.version_info >= (3, 9): # GenericAlias delegates attr access to `__origin__` def __getattr__(self, name: str) -> Any: ... -if sys.version_info >= (3, 10): - @final - class NoneType: - def __bool__(self) -> Literal[False]: ... - - @final - class EllipsisType: ... - - from builtins import _NotImplementedType - - NotImplementedType = _NotImplementedType +if sys.version_info >= (3, 14): + UnionType = Union +elif sys.version_info >= (3, 10): @final class UnionType: @property @@ -694,6 +686,17 @@ if sys.version_info >= (3, 10): def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... + @final + class NoneType: + def __bool__(self) -> Literal[False]: ... + + @final + class EllipsisType: ... + + from builtins import _NotImplementedType + + NotImplementedType = _NotImplementedType + if sys.version_info >= (3, 13): @final class CapsuleType: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 1ab5dae09cb4..72a416d98755 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -201,7 +201,22 @@ class _SpecialForm(_Final): def __or__(self, other: Any) -> _SpecialForm: ... def __ror__(self, other: Any) -> _SpecialForm: ... -Union: _SpecialForm +if sys.version_info >= (3, 14): + @final + class Union: + @property + def __args__(self) -> tuple[Any, ...]: ... + @property + def __parameters__(self) -> tuple[Any, ...]: ... + def __or__(self, value: Any, /) -> UnionType: ... + def __ror__(self, value: Any, /) -> UnionType: ... + def __eq__(self, value: object, /) -> bool: ... + def __hash__(self) -> int: ... + def __class_getitem__(cls, item: Any) -> Self: ... + +else: + Union: _SpecialForm + Generic: _SpecialForm # Protocol is only present in 3.8 and later, but mypy needs it unconditionally Protocol: _SpecialForm