Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update typing.Union and types.UnionType definitions for 3.14
  • Loading branch information
Viicos committed Mar 29, 2025
commit c7ec2158ea81579e523169def13788eb3dccf8a4
27 changes: 15 additions & 12 deletions stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand Down Expand Up @@ -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
Expand All @@ -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: ...
17 changes: 16 additions & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down