Skip to content

Commit 3944c78

Browse files
authored
Add __hash__ for a bunch of types that set it to None (#13286)
1 parent 1f0a86c commit 3944c78

32 files changed

Lines changed: 69 additions & 27 deletions

stdlib/_collections_abc.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from typing import ( # noqa: Y022,Y038
88
AsyncIterator as AsyncIterator,
99
Awaitable as Awaitable,
1010
Callable as Callable,
11+
ClassVar,
1112
Collection as Collection,
1213
Container as Container,
1314
Coroutine as Coroutine,
@@ -74,6 +75,7 @@ _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
7475
class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented
7576
def __eq__(self, value: object, /) -> bool: ...
7677
def __reversed__(self) -> Iterator[_KT_co]: ...
78+
__hash__: ClassVar[None] # type: ignore[assignment]
7779
if sys.version_info >= (3, 13):
7880
def isdisjoint(self, other: Iterable[_KT_co], /) -> bool: ...
7981
if sys.version_info >= (3, 10):
@@ -91,6 +93,7 @@ class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented
9193
class dict_items(ItemsView[_KT_co, _VT_co]): # undocumented
9294
def __eq__(self, value: object, /) -> bool: ...
9395
def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
96+
__hash__: ClassVar[None] # type: ignore[assignment]
9497
if sys.version_info >= (3, 13):
9598
def isdisjoint(self, other: Iterable[tuple[_KT_co, _VT_co]], /) -> bool: ...
9699
if sys.version_info >= (3, 10):

stdlib/_contextvars.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Token(Generic[_T]):
3737
@property
3838
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
3939
MISSING: ClassVar[object]
40+
__hash__: ClassVar[None] # type: ignore[assignment]
4041
if sys.version_info >= (3, 9):
4142
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4243

@@ -55,6 +56,7 @@ class Context(Mapping[ContextVar[Any], Any]):
5556
def get(self, key: ContextVar[_T], default: _D, /) -> _T | _D: ...
5657
def run(self, callable: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
5758
def copy(self) -> Context: ...
59+
__hash__: ClassVar[None] # type: ignore[assignment]
5860
def __getitem__(self, key: ContextVar[_T], /) -> _T: ...
5961
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
6062
def __len__(self) -> int: ...

stdlib/_frozen_importlib.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import types
55
from _typeshed.importlib import LoaderProtocol
66
from collections.abc import Mapping, Sequence
77
from types import ModuleType
8-
from typing import Any
8+
from typing import Any, ClassVar
99

1010
# Signature of `builtins.__import__` should be kept identical to `importlib.__import__`
1111
def __import__(
@@ -43,6 +43,7 @@ class ModuleSpec:
4343
def parent(self) -> str | None: ...
4444
has_location: bool
4545
def __eq__(self, other: object) -> bool: ...
46+
__hash__: ClassVar[None] # type: ignore[assignment]
4647

4748
class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
4849
# MetaPathFinder

stdlib/_ssl.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from ssl import (
1212
SSLWantWriteError as SSLWantWriteError,
1313
SSLZeroReturnError as SSLZeroReturnError,
1414
)
15-
from typing import Any, Literal, TypedDict, final, overload
15+
from typing import Any, ClassVar, Literal, TypedDict, final, overload
1616
from typing_extensions import NotRequired, Self, TypeAlias
1717

1818
_PasswordType: TypeAlias = Callable[[], str | bytes | bytearray] | str | bytes | bytearray
@@ -119,6 +119,7 @@ class MemoryBIO:
119119

120120
@final
121121
class SSLSession:
122+
__hash__: ClassVar[None] # type: ignore[assignment]
122123
@property
123124
def has_ticket(self) -> bool: ...
124125
@property

stdlib/_weakrefset.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from collections.abc import Iterable, Iterator, MutableSet
3-
from typing import Any, TypeVar, overload
3+
from typing import Any, ClassVar, TypeVar, overload
44
from typing_extensions import Self
55

66
if sys.version_info >= (3, 9):
@@ -21,6 +21,7 @@ class WeakSet(MutableSet[_T]):
2121
def copy(self) -> Self: ...
2222
def remove(self, item: _T) -> None: ...
2323
def update(self, other: Iterable[_T]) -> None: ...
24+
__hash__: ClassVar[None] # type: ignore[assignment]
2425
def __contains__(self, item: object) -> bool: ...
2526
def __len__(self) -> int: ...
2627
def __iter__(self) -> Iterator[_T]: ...

stdlib/argparse.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import sentinel
33
from collections.abc import Callable, Generator, Iterable, Sequence
44
from re import Pattern
5-
from typing import IO, Any, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
5+
from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
66
from typing_extensions import Self, TypeAlias, deprecated
77

88
__all__ = [
@@ -456,6 +456,7 @@ class Namespace(_AttributeHolder):
456456
def __setattr__(self, name: str, value: Any, /) -> None: ...
457457
def __contains__(self, key: str) -> bool: ...
458458
def __eq__(self, other: object) -> bool: ...
459+
__hash__: ClassVar[None] # type: ignore[assignment]
459460

460461
class FileType:
461462
# undocumented

stdlib/array.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite
33
from collections.abc import Iterable
44

55
# pytype crashes if array inherits from collections.abc.MutableSequence instead of typing.MutableSequence
6-
from typing import Any, Literal, MutableSequence, SupportsIndex, TypeVar, overload # noqa: Y022
6+
from typing import Any, ClassVar, Literal, MutableSequence, SupportsIndex, TypeVar, overload # noqa: Y022
77
from typing_extensions import Self, TypeAlias
88

99
if sys.version_info >= (3, 12):
@@ -64,6 +64,7 @@ class array(MutableSequence[_T]):
6464
def fromstring(self, buffer: str | ReadableBuffer, /) -> None: ...
6565
def tostring(self) -> bytes: ...
6666

67+
__hash__: ClassVar[None] # type: ignore[assignment]
6768
def __len__(self) -> int: ...
6869
@overload
6970
def __getitem__(self, key: SupportsIndex, /) -> _T: ...

stdlib/collections/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from _collections_abc import dict_items, dict_keys, dict_values
33
from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
4-
from typing import Any, Generic, NoReturn, SupportsIndex, TypeVar, final, overload
4+
from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload
55
from typing_extensions import Self
66

77
if sys.version_info >= (3, 9):
@@ -119,6 +119,7 @@ class UserList(MutableSequence[_T]):
119119
def __init__(self, initlist: None = None) -> None: ...
120120
@overload
121121
def __init__(self, initlist: Iterable[_T]) -> None: ...
122+
__hash__: ClassVar[None] # type: ignore[assignment]
122123
def __lt__(self, other: list[_T] | UserList[_T]) -> bool: ...
123124
def __le__(self, other: list[_T] | UserList[_T]) -> bool: ...
124125
def __gt__(self, other: list[_T] | UserList[_T]) -> bool: ...
@@ -254,6 +255,7 @@ class deque(MutableSequence[_T]):
254255
def rotate(self, n: int = 1, /) -> None: ...
255256
def __copy__(self) -> Self: ...
256257
def __len__(self) -> int: ...
258+
__hash__: ClassVar[None] # type: ignore[assignment]
257259
# These methods of deque don't take slices, unlike MutableSequence, hence the type: ignores
258260
def __getitem__(self, key: SupportsIndex, /) -> _T: ... # type: ignore[override]
259261
def __setitem__(self, key: SupportsIndex, value: _T, /) -> None: ... # type: ignore[override]

stdlib/email/charset.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Callable, Iterator
22
from email.message import Message
3-
from typing import Final, overload
3+
from typing import ClassVar, Final, overload
44

55
__all__ = ["Charset", "add_alias", "add_charset", "add_codec"]
66

@@ -24,6 +24,7 @@ class Charset:
2424
def body_encode(self, string: None) -> None: ...
2525
@overload
2626
def body_encode(self, string: str | bytes) -> str: ...
27+
__hash__: ClassVar[None] # type: ignore[assignment]
2728
def __eq__(self, other: object) -> bool: ...
2829
def __ne__(self, value: object, /) -> bool: ...
2930

stdlib/email/header.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Iterable
22
from email.charset import Charset
3-
from typing import Any
3+
from typing import Any, ClassVar
44

55
__all__ = ["Header", "decode_header", "make_header"]
66

@@ -16,6 +16,7 @@ class Header:
1616
) -> None: ...
1717
def append(self, s: bytes | bytearray | str, charset: Charset | str | None = None, errors: str = "strict") -> None: ...
1818
def encode(self, splitchars: str = ";, \t", maxlinelen: int | None = None, linesep: str = "\n") -> str: ...
19+
__hash__: ClassVar[None] # type: ignore[assignment]
1920
def __eq__(self, other: object) -> bool: ...
2021
def __ne__(self, value: object, /) -> bool: ...
2122

0 commit comments

Comments
 (0)