Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if sys.version_info < (3, 15):
if sys.version_info >= (3, 12):
__all__ += ["Buffer"]

_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
_KT_co = TypeVar("_KT_co", bound=Hashable, covariant=True) # Key type covariant containers.
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.

@final
Expand Down
131 changes: 68 additions & 63 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ from _typeshed import (
SupportsRichComparisonT,
SupportsWrite,
)
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
from collections.abc import Awaitable, Callable, Hashable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
from os import PathLike
from types import CellType, CodeType, EllipsisType, GenericAlias, NotImplementedType, TracebackType
Expand Down Expand Up @@ -75,14 +75,19 @@ _I = TypeVar("_I", default=int)
_T_co = TypeVar("_T_co", covariant=True)
_T_contra = TypeVar("_T_contra", contravariant=True)
_R_co = TypeVar("_R_co", covariant=True)
_KT = TypeVar("_KT")
_KT = TypeVar("_KT", bound=Hashable)
_VT = TypeVar("_VT")
_S = TypeVar("_S")
_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
_T3 = TypeVar("_T3")
_T4 = TypeVar("_T4")
_T5 = TypeVar("_T5")
_H1 = TypeVar("_H1", bound=Hashable)
_H2 = TypeVar("_H2", bound=Hashable)
_H1_co = TypeVar("_H1_co", bound=Hashable)
_H2_co = TypeVar("_H2_co", bound=Hashable)

_SupportsNextT_co = TypeVar("_SupportsNextT_co", bound=SupportsNext[Any], covariant=True)
_SupportsAnextT_co = TypeVar("_SupportsAnextT_co", bound=SupportsAnext[Any], covariant=True)
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
Expand Down Expand Up @@ -1226,10 +1231,10 @@ class dict(MutableMapping[_KT, _VT]):
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
@classmethod
@overload
def fromkeys(cls, iterable: Iterable[_T], value: None = None, /) -> dict[_T, Any | None]: ...
def fromkeys(cls, iterable: Iterable[_H1], value: None = None, /) -> dict[_H1, Any | None]: ...
@classmethod
@overload
def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> dict[_T, _S]: ...
def fromkeys(cls, iterable: Iterable[_H1], value: _T, /) -> dict[_H1, _T]: ...
# Positional-only in dict, but not in MutableMapping
@overload # type: ignore[override]
def get(self, key: _KT, default: None = None, /) -> _VT | None: ...
Expand All @@ -1253,14 +1258,14 @@ class dict(MutableMapping[_KT, _VT]):
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
if sys.version_info >= (3, 15):
def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
def __or__(self, value: dict[_H1, _T] | frozendict[_H1, _T], /) -> dict[_KT | _H1, _VT | _T]: ...
@overload
def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
def __ror__(self, value: dict[_H1, _T], /) -> dict[_KT | _H1, _VT | _T]: ...
@overload
def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ...
def __ror__(self, value: frozendict[_H1, _T], /) -> frozendict[_KT | _H1, _VT | _T]: ...
else:
def __or__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
def __or__(self, value: dict[_H1, _T], /) -> dict[_KT | _H1, _VT | _T]: ...
def __ror__(self, value: dict[_H1, _T], /) -> dict[_KT | _H1, _VT | _T]: ...
# dict.__ior__ should be kept roughly in line with MutableMapping.update()
@overload # type: ignore[misc]
def __ior__(self, value: SupportsKeysAndGetItem[_KT, _VT], /) -> Self: ...
Expand All @@ -1271,7 +1276,7 @@ if sys.version_info >= (3, 15):
@disjoint_base
class frozendict(Mapping[_KT, _VT]):
@overload
def __new__(cls, /) -> frozendict[Any, Any]: ...
def __new__(cls, /) -> frozendict[Hashable, Any]: ...
@overload
def __new__(cls: type[frozendict[str, _VT]], /, **kwargs: _VT) -> frozendict[str, _VT]: ...
@overload
Expand All @@ -1290,10 +1295,10 @@ if sys.version_info >= (3, 15):
def copy(self) -> frozendict[_KT, _VT]: ...
@overload
@classmethod
def fromkeys(cls, iterable: Iterable[_T], value: None = None, /) -> frozendict[_T, Any | None]: ...
def fromkeys(cls, iterable: Iterable[_H1], value: None = None, /) -> frozendict[_H1, Any | None]: ...
@overload
@classmethod
def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> frozendict[_T, _S]: ...
def fromkeys(cls, iterable: Iterable[_H1], value: _T, /) -> frozendict[_H1, _T]: ...
@overload # type: ignore[override]
def get(self, key: _KT, default: None = None, /) -> _VT | None: ...
@overload
Expand All @@ -1316,70 +1321,70 @@ if sys.version_info >= (3, 15):
def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ...

@disjoint_base
class set(MutableSet[_T]):
class set(MutableSet[_H1]):
@overload
def __init__(self) -> None: ...
@overload
def __init__(self, iterable: Iterable[_T], /) -> None: ...
def add(self, element: _T, /) -> None: ...
def copy(self) -> set[_T]: ...
def difference(self, *s: Iterable[object]) -> set[_T]: ...
def difference_update(self, *s: Iterable[object]) -> None: ...
def discard(self, element: object, /) -> None: ...
def intersection(self, *s: Iterable[object]) -> set[_T]: ...
def intersection_update(self, *s: Iterable[object]) -> None: ...
def isdisjoint(self, s: Iterable[object], /) -> bool: ...
def issubset(self, s: Iterable[object], /) -> bool: ...
def issuperset(self, s: Iterable[object], /) -> bool: ...
def remove(self, element: _T, /) -> None: ...
def symmetric_difference(self, s: Iterable[_S], /) -> set[_T | _S]: ...
def symmetric_difference_update(self, s: Iterable[_T], /) -> None: ...
def union(self, *s: Iterable[_S]) -> set[_T | _S]: ...
def update(self, *s: Iterable[_T]) -> None: ...
def __init__(self, iterable: Iterable[_H1], /) -> None: ...
def add(self, element: _H1, /) -> None: ...
def copy(self) -> set[_H1]: ...
def difference(self, *s: Iterable[Hashable]) -> set[_H1]: ...
def difference_update(self, *s: Iterable[Hashable]) -> None: ...
def discard(self, element: Hashable, /) -> None: ...
def intersection(self, *s: Iterable[Hashable]) -> set[_H1]: ...
def intersection_update(self, *s: Iterable[Hashable]) -> None: ...
def isdisjoint(self, s: Iterable[Hashable], /) -> bool: ...
def issubset(self, s: Iterable[Hashable], /) -> bool: ...
def issuperset(self, s: Iterable[Hashable], /) -> bool: ...
def remove(self, element: _H1, /) -> None: ...
def symmetric_difference(self, s: Iterable[_H2], /) -> set[_H1 | _H2]: ...
def symmetric_difference_update(self, s: Iterable[_H1], /) -> None: ...
def union(self, *s: Iterable[_H2]) -> set[_H1 | _H2]: ...
def update(self, *s: Iterable[_H1]) -> None: ...
def __len__(self) -> int: ...
def __contains__(self, o: object, /) -> bool: ...
def __iter__(self) -> Iterator[_T]: ...
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __le__(self, value: AbstractSet[object], /) -> bool: ...
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __contains__(self, o: Hashable, /) -> bool: ...
def __iter__(self) -> Iterator[_H1]: ...
def __and__(self, value: AbstractSet[Hashable], /) -> set[_H1]: ...
def __iand__(self, value: AbstractSet[Hashable], /) -> Self: ...
def __or__(self, value: AbstractSet[_H2], /) -> set[_H1 | _H2]: ...
def __ior__(self, value: AbstractSet[_H1], /) -> Self: ... # type: ignore[override,misc]
def __sub__(self, value: AbstractSet[Hashable], /) -> set[_H1]: ...
def __isub__(self, value: AbstractSet[Hashable], /) -> Self: ...
def __xor__(self, value: AbstractSet[_H2], /) -> set[_H1 | _H2]: ...
def __ixor__(self, value: AbstractSet[_H1], /) -> Self: ... # type: ignore[override,misc]
def __le__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __lt__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __ge__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __gt__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

@disjoint_base
class frozenset(AbstractSet[_T_co]):
class frozenset(AbstractSet[_H1_co]):
@overload
def __new__(cls) -> Self: ...
@overload
def __new__(cls, iterable: Iterable[_T_co], /) -> Self: ...
def copy(self) -> frozenset[_T_co]: ...
def difference(self, *s: Iterable[object]) -> frozenset[_T_co]: ...
def intersection(self, *s: Iterable[object]) -> frozenset[_T_co]: ...
def isdisjoint(self, s: Iterable[object], /) -> bool: ...
def issubset(self, s: Iterable[object], /) -> bool: ...
def issuperset(self, s: Iterable[object], /) -> bool: ...
def symmetric_difference(self, s: Iterable[_S], /) -> frozenset[_T_co | _S]: ...
def union(self, *s: Iterable[_S]) -> frozenset[_T_co | _S]: ...
def __new__(cls, iterable: Iterable[_H1_co], /) -> Self: ...
def copy(self) -> frozenset[_H1_co]: ...
def difference(self, *s: Iterable[Hashable]) -> frozenset[_H1_co]: ...
def intersection(self, *s: Iterable[Hashable]) -> frozenset[_H1_co]: ...
def isdisjoint(self, s: Iterable[Hashable], /) -> bool: ...
def issubset(self, s: Iterable[Hashable], /) -> bool: ...
def issuperset(self, s: Iterable[Hashable], /) -> bool: ...
def symmetric_difference(self, s: Iterable[_H1], /) -> frozenset[_H1_co | _H1]: ...
def union(self, *s: Iterable[_H1]) -> frozenset[_H1_co | _H1]: ...
def __len__(self) -> int: ...
def __contains__(self, o: object, /) -> bool: ...
def __iter__(self) -> Iterator[_T_co]: ...
def __and__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
def __le__(self, value: AbstractSet[object], /) -> bool: ...
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __contains__(self, o: Hashable, /) -> bool: ...
def __iter__(self) -> Iterator[_H1_co]: ...
def __and__(self, value: AbstractSet[Hashable], /) -> frozenset[_H1_co]: ...
def __or__(self, value: AbstractSet[_H1], /) -> frozenset[_H1_co | _H1]: ...
def __sub__(self, value: AbstractSet[Hashable], /) -> frozenset[_H1_co]: ...
def __xor__(self, value: AbstractSet[_H1], /) -> frozenset[_H1_co | _H1]: ...
def __le__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __lt__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __ge__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __gt__(self, value: AbstractSet[Hashable], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __hash__(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
Expand Down
Loading
Loading