From 4308915e060c679a82c19126cc628a3312a9e738 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 19 Mar 2022 12:59:10 +0000 Subject: [PATCH] Make `__hash__` a `ClassVar` for several classes where it is set to `None` (#7485) --- stdlib/@python2/__builtin__.pyi | 11 ++++++----- stdlib/@python2/builtins.pyi | 11 ++++++----- stdlib/_tkinter.pyi | 4 ++-- stdlib/builtins.pyi | 11 ++++++----- stdlib/types.pyi | 7 ++++--- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/stdlib/@python2/__builtin__.pyi b/stdlib/@python2/__builtin__.pyi index b6ac2b78a..bb51cfe78 100644 --- a/stdlib/@python2/__builtin__.pyi +++ b/stdlib/@python2/__builtin__.pyi @@ -12,6 +12,7 @@ from typing import ( BinaryIO, ByteString, Callable, + ClassVar, Container, Generic, ItemsView, @@ -490,7 +491,7 @@ class bytearray(MutableSequence[int], ByteString): def __iter__(self) -> Iterator[int]: ... def __int__(self) -> int: ... def __float__(self) -> float: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore @overload def __getitem__(self, i: int) -> int: ... @overload @@ -574,7 +575,7 @@ class slice(object): def __init__(self, stop: Any) -> None: ... @overload def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore def indices(self, len: int) -> tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): @@ -621,7 +622,7 @@ class list(MutableSequence[_T], Generic[_T]): def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore @overload def __getitem__(self, i: int) -> _T: ... @overload @@ -683,7 +684,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __setitem__(self, k: _KT, v: _VT) -> None: ... def __delitem__(self, v: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore class set(MutableSet[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ...) -> None: ... @@ -725,7 +726,7 @@ class set(MutableSet[_T], Generic[_T]): def __lt__(self, s: AbstractSet[object]) -> bool: ... def __ge__(self, s: AbstractSet[object]) -> bool: ... def __gt__(self, s: AbstractSet[object]) -> bool: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore class frozenset(AbstractSet[_T_co], Generic[_T_co]): def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ... diff --git a/stdlib/@python2/builtins.pyi b/stdlib/@python2/builtins.pyi index b6ac2b78a..bb51cfe78 100644 --- a/stdlib/@python2/builtins.pyi +++ b/stdlib/@python2/builtins.pyi @@ -12,6 +12,7 @@ from typing import ( BinaryIO, ByteString, Callable, + ClassVar, Container, Generic, ItemsView, @@ -490,7 +491,7 @@ class bytearray(MutableSequence[int], ByteString): def __iter__(self) -> Iterator[int]: ... def __int__(self) -> int: ... def __float__(self) -> float: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore @overload def __getitem__(self, i: int) -> int: ... @overload @@ -574,7 +575,7 @@ class slice(object): def __init__(self, stop: Any) -> None: ... @overload def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore def indices(self, len: int) -> tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): @@ -621,7 +622,7 @@ class list(MutableSequence[_T], Generic[_T]): def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore @overload def __getitem__(self, i: int) -> _T: ... @overload @@ -683,7 +684,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __setitem__(self, k: _KT, v: _VT) -> None: ... def __delitem__(self, v: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore class set(MutableSet[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ...) -> None: ... @@ -725,7 +726,7 @@ class set(MutableSet[_T], Generic[_T]): def __lt__(self, s: AbstractSet[object]) -> bool: ... def __ge__(self, s: AbstractSet[object]) -> bool: ... def __gt__(self, s: AbstractSet[object]) -> bool: ... - __hash__: None # type: ignore + __hash__: ClassVar[None] # type: ignore class frozenset(AbstractSet[_T_co], Generic[_T_co]): def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ... diff --git a/stdlib/_tkinter.pyi b/stdlib/_tkinter.pyi index 6dfe070da..c2cf55505 100644 --- a/stdlib/_tkinter.pyi +++ b/stdlib/_tkinter.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any +from typing import Any, ClassVar from typing_extensions import Literal, final # _tkinter is meant to be only used internally by tkinter, but some tkinter @@ -19,7 +19,7 @@ from typing_extensions import Literal, final class Tcl_Obj: string: str | bytes typename: str - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] def __eq__(self, __other): ... def __ge__(self, __other): ... def __gt__(self, __other): ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index a347092e0..5a834b417 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -32,6 +32,7 @@ from typing import ( Awaitable, BinaryIO, ByteString, + ClassVar, Generic, Iterable, Iterator, @@ -656,7 +657,7 @@ class bytearray(MutableSequence[int], ByteString): def maketrans(__frm: bytes, __to: bytes) -> bytes: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ... - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] @overload def __getitem__(self, __i: SupportsIndex) -> int: ... @overload @@ -783,7 +784,7 @@ class slice: def __init__(self, __stop: Any) -> None: ... @overload def __init__(self, __start: Any, __stop: Any, __step: Any = ...) -> None: ... - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): @@ -854,7 +855,7 @@ class list(MutableSequence[_T], Generic[_T]): def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] @overload def __getitem__(self, __i: SupportsIndex) -> _T: ... @overload @@ -922,7 +923,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... if sys.version_info >= (3, 8): def __reversed__(self) -> Iterator[_KT]: ... - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] if sys.version_info >= (3, 9): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ... @@ -965,7 +966,7 @@ class set(MutableSet[_T], Generic[_T]): def __lt__(self, __s: AbstractSet[object]) -> bool: ... def __ge__(self, __s: AbstractSet[object]) -> bool: ... def __gt__(self, __s: AbstractSet[object]) -> bool: ... - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] if sys.version_info >= (3, 9): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 510f8d9eb..a1873f30c 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -7,6 +7,7 @@ from typing import ( AsyncGenerator, Awaitable, Callable, + ClassVar, Coroutine, Generator, Generic, @@ -178,7 +179,7 @@ _V_co = TypeVar("_V_co", covariant=True) @final class _Cell: - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] cell_contents: Any # Make sure this class definition stays roughly in line with `builtins.function` @@ -340,7 +341,7 @@ class CodeType: @final class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]): - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] def __init__(self, mapping: SupportsKeysAndGetItem[_KT, _VT_co]) -> None: ... def __getitem__(self, __k: _KT) -> _VT_co: ... def __iter__(self) -> Iterator[_KT]: ... @@ -356,7 +357,7 @@ class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]): def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT_co | _T2]: ... class SimpleNamespace: - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] def __init__(self, **kwargs: Any) -> None: ... def __getattribute__(self, __name: str) -> Any: ... def __setattr__(self, __name: str, __value: Any) -> None: ...