Skip to content

Commit 4308915

Browse files
authored
Make __hash__ a ClassVar for several classes where it is set to None (#7485)
1 parent d9f1f7b commit 4308915

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

stdlib/@python2/__builtin__.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from typing import (
1212
BinaryIO,
1313
ByteString,
1414
Callable,
15+
ClassVar,
1516
Container,
1617
Generic,
1718
ItemsView,
@@ -490,7 +491,7 @@ class bytearray(MutableSequence[int], ByteString):
490491
def __iter__(self) -> Iterator[int]: ...
491492
def __int__(self) -> int: ...
492493
def __float__(self) -> float: ...
493-
__hash__: None # type: ignore
494+
__hash__: ClassVar[None] # type: ignore
494495
@overload
495496
def __getitem__(self, i: int) -> int: ...
496497
@overload
@@ -574,7 +575,7 @@ class slice(object):
574575
def __init__(self, stop: Any) -> None: ...
575576
@overload
576577
def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ...
577-
__hash__: None # type: ignore
578+
__hash__: ClassVar[None] # type: ignore
578579
def indices(self, len: int) -> tuple[int, int, int]: ...
579580

580581
class tuple(Sequence[_T_co], Generic[_T_co]):
@@ -621,7 +622,7 @@ class list(MutableSequence[_T], Generic[_T]):
621622
def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ...
622623
def __len__(self) -> int: ...
623624
def __iter__(self) -> Iterator[_T]: ...
624-
__hash__: None # type: ignore
625+
__hash__: ClassVar[None] # type: ignore
625626
@overload
626627
def __getitem__(self, i: int) -> _T: ...
627628
@overload
@@ -683,7 +684,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
683684
def __setitem__(self, k: _KT, v: _VT) -> None: ...
684685
def __delitem__(self, v: _KT) -> None: ...
685686
def __iter__(self) -> Iterator[_KT]: ...
686-
__hash__: None # type: ignore
687+
__hash__: ClassVar[None] # type: ignore
687688

688689
class set(MutableSet[_T], Generic[_T]):
689690
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...
@@ -725,7 +726,7 @@ class set(MutableSet[_T], Generic[_T]):
725726
def __lt__(self, s: AbstractSet[object]) -> bool: ...
726727
def __ge__(self, s: AbstractSet[object]) -> bool: ...
727728
def __gt__(self, s: AbstractSet[object]) -> bool: ...
728-
__hash__: None # type: ignore
729+
__hash__: ClassVar[None] # type: ignore
729730

730731
class frozenset(AbstractSet[_T_co], Generic[_T_co]):
731732
def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ...

stdlib/@python2/builtins.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from typing import (
1212
BinaryIO,
1313
ByteString,
1414
Callable,
15+
ClassVar,
1516
Container,
1617
Generic,
1718
ItemsView,
@@ -490,7 +491,7 @@ class bytearray(MutableSequence[int], ByteString):
490491
def __iter__(self) -> Iterator[int]: ...
491492
def __int__(self) -> int: ...
492493
def __float__(self) -> float: ...
493-
__hash__: None # type: ignore
494+
__hash__: ClassVar[None] # type: ignore
494495
@overload
495496
def __getitem__(self, i: int) -> int: ...
496497
@overload
@@ -574,7 +575,7 @@ class slice(object):
574575
def __init__(self, stop: Any) -> None: ...
575576
@overload
576577
def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ...
577-
__hash__: None # type: ignore
578+
__hash__: ClassVar[None] # type: ignore
578579
def indices(self, len: int) -> tuple[int, int, int]: ...
579580

580581
class tuple(Sequence[_T_co], Generic[_T_co]):
@@ -621,7 +622,7 @@ class list(MutableSequence[_T], Generic[_T]):
621622
def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ...
622623
def __len__(self) -> int: ...
623624
def __iter__(self) -> Iterator[_T]: ...
624-
__hash__: None # type: ignore
625+
__hash__: ClassVar[None] # type: ignore
625626
@overload
626627
def __getitem__(self, i: int) -> _T: ...
627628
@overload
@@ -683,7 +684,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
683684
def __setitem__(self, k: _KT, v: _VT) -> None: ...
684685
def __delitem__(self, v: _KT) -> None: ...
685686
def __iter__(self) -> Iterator[_KT]: ...
686-
__hash__: None # type: ignore
687+
__hash__: ClassVar[None] # type: ignore
687688

688689
class set(MutableSet[_T], Generic[_T]):
689690
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...
@@ -725,7 +726,7 @@ class set(MutableSet[_T], Generic[_T]):
725726
def __lt__(self, s: AbstractSet[object]) -> bool: ...
726727
def __ge__(self, s: AbstractSet[object]) -> bool: ...
727728
def __gt__(self, s: AbstractSet[object]) -> bool: ...
728-
__hash__: None # type: ignore
729+
__hash__: ClassVar[None] # type: ignore
729730

730731
class frozenset(AbstractSet[_T_co], Generic[_T_co]):
731732
def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ...

stdlib/_tkinter.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from typing import Any
2+
from typing import Any, ClassVar
33
from typing_extensions import Literal, final
44

55
# _tkinter is meant to be only used internally by tkinter, but some tkinter
@@ -19,7 +19,7 @@ from typing_extensions import Literal, final
1919
class Tcl_Obj:
2020
string: str | bytes
2121
typename: str
22-
__hash__: None # type: ignore[assignment]
22+
__hash__: ClassVar[None] # type: ignore[assignment]
2323
def __eq__(self, __other): ...
2424
def __ge__(self, __other): ...
2525
def __gt__(self, __other): ...

stdlib/builtins.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ from typing import (
3232
Awaitable,
3333
BinaryIO,
3434
ByteString,
35+
ClassVar,
3536
Generic,
3637
Iterable,
3738
Iterator,
@@ -656,7 +657,7 @@ class bytearray(MutableSequence[int], ByteString):
656657
def maketrans(__frm: bytes, __to: bytes) -> bytes: ...
657658
def __len__(self) -> int: ...
658659
def __iter__(self) -> Iterator[int]: ...
659-
__hash__: None # type: ignore[assignment]
660+
__hash__: ClassVar[None] # type: ignore[assignment]
660661
@overload
661662
def __getitem__(self, __i: SupportsIndex) -> int: ...
662663
@overload
@@ -783,7 +784,7 @@ class slice:
783784
def __init__(self, __stop: Any) -> None: ...
784785
@overload
785786
def __init__(self, __start: Any, __stop: Any, __step: Any = ...) -> None: ...
786-
__hash__: None # type: ignore[assignment]
787+
__hash__: ClassVar[None] # type: ignore[assignment]
787788
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
788789

789790
class tuple(Sequence[_T_co], Generic[_T_co]):
@@ -854,7 +855,7 @@ class list(MutableSequence[_T], Generic[_T]):
854855
def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ...
855856
def __len__(self) -> int: ...
856857
def __iter__(self) -> Iterator[_T]: ...
857-
__hash__: None # type: ignore[assignment]
858+
__hash__: ClassVar[None] # type: ignore[assignment]
858859
@overload
859860
def __getitem__(self, __i: SupportsIndex) -> _T: ...
860861
@overload
@@ -922,7 +923,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
922923
def __iter__(self) -> Iterator[_KT]: ...
923924
if sys.version_info >= (3, 8):
924925
def __reversed__(self) -> Iterator[_KT]: ...
925-
__hash__: None # type: ignore[assignment]
926+
__hash__: ClassVar[None] # type: ignore[assignment]
926927
if sys.version_info >= (3, 9):
927928
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
928929
def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
@@ -965,7 +966,7 @@ class set(MutableSet[_T], Generic[_T]):
965966
def __lt__(self, __s: AbstractSet[object]) -> bool: ...
966967
def __ge__(self, __s: AbstractSet[object]) -> bool: ...
967968
def __gt__(self, __s: AbstractSet[object]) -> bool: ...
968-
__hash__: None # type: ignore[assignment]
969+
__hash__: ClassVar[None] # type: ignore[assignment]
969970
if sys.version_info >= (3, 9):
970971
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
971972

stdlib/types.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from typing import (
77
AsyncGenerator,
88
Awaitable,
99
Callable,
10+
ClassVar,
1011
Coroutine,
1112
Generator,
1213
Generic,
@@ -178,7 +179,7 @@ _V_co = TypeVar("_V_co", covariant=True)
178179

179180
@final
180181
class _Cell:
181-
__hash__: None # type: ignore[assignment]
182+
__hash__: ClassVar[None] # type: ignore[assignment]
182183
cell_contents: Any
183184

184185
# Make sure this class definition stays roughly in line with `builtins.function`
@@ -340,7 +341,7 @@ class CodeType:
340341

341342
@final
342343
class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]):
343-
__hash__: None # type: ignore[assignment]
344+
__hash__: ClassVar[None] # type: ignore[assignment]
344345
def __init__(self, mapping: SupportsKeysAndGetItem[_KT, _VT_co]) -> None: ...
345346
def __getitem__(self, __k: _KT) -> _VT_co: ...
346347
def __iter__(self) -> Iterator[_KT]: ...
@@ -356,7 +357,7 @@ class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]):
356357
def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT_co | _T2]: ...
357358

358359
class SimpleNamespace:
359-
__hash__: None # type: ignore[assignment]
360+
__hash__: ClassVar[None] # type: ignore[assignment]
360361
def __init__(self, **kwargs: Any) -> None: ...
361362
def __getattribute__(self, __name: str) -> Any: ...
362363
def __setattr__(self, __name: str, __value: Any) -> None: ...

0 commit comments

Comments
 (0)