Skip to content

Commit a7f7ee1

Browse files
committed
harmonize builtins and typing_extensions, fix various __(r)or__ methods
1 parent 6b08478 commit a7f7ee1

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

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+
# `sentinel("X") | sentinel("X")` creates a `sentinel` instance, 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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,11 +687,15 @@ else:
687687
class sentinel:
688688
def __init__(self, name: str, /, *, repr: str | None = None) -> None: ...
689689
__name__: str
690+
__module__: str
690691
if sys.version_info >= (3, 14):
691-
def __or__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions
692-
def __ror__(self, other: Any) -> UnionType: ... # other can be any type form legal for unions
692+
# `other`` can be any type form legal for unions.
693+
# `sentinel("X") | sentinel("X")` creates a `sentinel` instance, not a `UnionType` instance
694+
def __or__(self, other: Any) -> UnionType | sentinel: ...
695+
def __ror__(self, other: Any) -> UnionType | sentinel: ...
693696
else:
694-
def __or__(self, other: Any) -> _SpecialForm: ... # other can be any type form legal for unions
695-
def __ror__(self, other: Any) -> _SpecialForm: ... # other can be any type form legal for unions
697+
# other can be any type form legal for unions
698+
def __or__(self, other: Any) -> _SpecialForm: ...
699+
def __ror__(self, other: Any) -> _SpecialForm: ...
696700

697701
Sentinel = sentinel

0 commit comments

Comments
 (0)