Make __hash__ a ClassVar for several classes where it is set to None (#7485)

This commit is contained in:
Alex Waygood
2022-03-19 12:59:10 +00:00
committed by GitHub
parent d9f1f7b81f
commit 4308915e06
5 changed files with 24 additions and 20 deletions

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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): ...

View File

@@ -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: ...

View File

@@ -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: ...