Add __hash__ for a bunch of types that set it to None (#13286)

This commit is contained in:
Stephen Morton
2024-12-23 23:16:22 -08:00
committed by GitHub
parent 1f0a86ceb4
commit 3944c7839e
32 changed files with 69 additions and 27 deletions

View File

@@ -8,6 +8,7 @@ from typing import ( # noqa: Y022,Y038
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
Callable as Callable,
ClassVar,
Collection as Collection,
Container as Container,
Coroutine as Coroutine,
@@ -74,6 +75,7 @@ _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented
def __eq__(self, value: object, /) -> bool: ...
def __reversed__(self) -> Iterator[_KT_co]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
if sys.version_info >= (3, 13):
def isdisjoint(self, other: Iterable[_KT_co], /) -> bool: ...
if sys.version_info >= (3, 10):
@@ -91,6 +93,7 @@ class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented
class dict_items(ItemsView[_KT_co, _VT_co]): # undocumented
def __eq__(self, value: object, /) -> bool: ...
def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
if sys.version_info >= (3, 13):
def isdisjoint(self, other: Iterable[tuple[_KT_co, _VT_co]], /) -> bool: ...
if sys.version_info >= (3, 10):

View File

@@ -37,6 +37,7 @@ class Token(Generic[_T]):
@property
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
MISSING: ClassVar[object]
__hash__: ClassVar[None] # type: ignore[assignment]
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
@@ -55,6 +56,7 @@ class Context(Mapping[ContextVar[Any], Any]):
def get(self, key: ContextVar[_T], default: _D, /) -> _T | _D: ...
def run(self, callable: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
def copy(self) -> Context: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __getitem__(self, key: ContextVar[_T], /) -> _T: ...
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
def __len__(self) -> int: ...

View File

@@ -5,7 +5,7 @@ import types
from _typeshed.importlib import LoaderProtocol
from collections.abc import Mapping, Sequence
from types import ModuleType
from typing import Any
from typing import Any, ClassVar
# Signature of `builtins.__import__` should be kept identical to `importlib.__import__`
def __import__(
@@ -43,6 +43,7 @@ class ModuleSpec:
def parent(self) -> str | None: ...
has_location: bool
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
# MetaPathFinder

View File

@@ -12,7 +12,7 @@ from ssl import (
SSLWantWriteError as SSLWantWriteError,
SSLZeroReturnError as SSLZeroReturnError,
)
from typing import Any, Literal, TypedDict, final, overload
from typing import Any, ClassVar, Literal, TypedDict, final, overload
from typing_extensions import NotRequired, Self, TypeAlias
_PasswordType: TypeAlias = Callable[[], str | bytes | bytearray] | str | bytes | bytearray
@@ -119,6 +119,7 @@ class MemoryBIO:
@final
class SSLSession:
__hash__: ClassVar[None] # type: ignore[assignment]
@property
def has_ticket(self) -> bool: ...
@property

View File

@@ -1,6 +1,6 @@
import sys
from collections.abc import Iterable, Iterator, MutableSet
from typing import Any, TypeVar, overload
from typing import Any, ClassVar, TypeVar, overload
from typing_extensions import Self
if sys.version_info >= (3, 9):
@@ -21,6 +21,7 @@ class WeakSet(MutableSet[_T]):
def copy(self) -> Self: ...
def remove(self, item: _T) -> None: ...
def update(self, other: Iterable[_T]) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __contains__(self, item: object) -> bool: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[_T]: ...

View File

@@ -2,7 +2,7 @@ import sys
from _typeshed import sentinel
from collections.abc import Callable, Generator, Iterable, Sequence
from re import Pattern
from typing import IO, Any, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
from typing_extensions import Self, TypeAlias, deprecated
__all__ = [
@@ -456,6 +456,7 @@ class Namespace(_AttributeHolder):
def __setattr__(self, name: str, value: Any, /) -> None: ...
def __contains__(self, key: str) -> bool: ...
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
class FileType:
# undocumented

View File

@@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite
from collections.abc import Iterable
# pytype crashes if array inherits from collections.abc.MutableSequence instead of typing.MutableSequence
from typing import Any, Literal, MutableSequence, SupportsIndex, TypeVar, overload # noqa: Y022
from typing import Any, ClassVar, Literal, MutableSequence, SupportsIndex, TypeVar, overload # noqa: Y022
from typing_extensions import Self, TypeAlias
if sys.version_info >= (3, 12):
@@ -64,6 +64,7 @@ class array(MutableSequence[_T]):
def fromstring(self, buffer: str | ReadableBuffer, /) -> None: ...
def tostring(self) -> bytes: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __len__(self) -> int: ...
@overload
def __getitem__(self, key: SupportsIndex, /) -> _T: ...

View File

@@ -1,7 +1,7 @@
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from typing import Any, Generic, NoReturn, SupportsIndex, TypeVar, final, overload
from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload
from typing_extensions import Self
if sys.version_info >= (3, 9):
@@ -119,6 +119,7 @@ class UserList(MutableSequence[_T]):
def __init__(self, initlist: None = None) -> None: ...
@overload
def __init__(self, initlist: Iterable[_T]) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __lt__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __le__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __gt__(self, other: list[_T] | UserList[_T]) -> bool: ...
@@ -254,6 +255,7 @@ class deque(MutableSequence[_T]):
def rotate(self, n: int = 1, /) -> None: ...
def __copy__(self) -> Self: ...
def __len__(self) -> int: ...
__hash__: ClassVar[None] # type: ignore[assignment]
# These methods of deque don't take slices, unlike MutableSequence, hence the type: ignores
def __getitem__(self, key: SupportsIndex, /) -> _T: ... # type: ignore[override]
def __setitem__(self, key: SupportsIndex, value: _T, /) -> None: ... # type: ignore[override]

View File

@@ -1,6 +1,6 @@
from collections.abc import Callable, Iterator
from email.message import Message
from typing import Final, overload
from typing import ClassVar, Final, overload
__all__ = ["Charset", "add_alias", "add_charset", "add_codec"]
@@ -24,6 +24,7 @@ class Charset:
def body_encode(self, string: None) -> None: ...
@overload
def body_encode(self, string: str | bytes) -> str: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __eq__(self, other: object) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...

View File

@@ -1,6 +1,6 @@
from collections.abc import Iterable
from email.charset import Charset
from typing import Any
from typing import Any, ClassVar
__all__ = ["Header", "decode_header", "make_header"]
@@ -16,6 +16,7 @@ class Header:
) -> None: ...
def append(self, s: bytes | bytearray | str, charset: Charset | str | None = None, errors: str = "strict") -> None: ...
def encode(self, splitchars: str = ";, \t", maxlinelen: int | None = None, linesep: str = "\n") -> str: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __eq__(self, other: object) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...

View File

@@ -167,6 +167,7 @@ class Address:
def __init__(
self, display_name: str = "", username: str | None = "", domain: str | None = "", addr_spec: str | None = None
) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __eq__(self, other: object) -> bool: ...
class Group:
@@ -175,4 +176,5 @@ class Group:
@property
def addresses(self) -> tuple[Address, ...]: ...
def __init__(self, display_name: str | None = None, addresses: Iterable[Address] | None = None) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __eq__(self, other: object) -> bool: ...

View File

@@ -138,7 +138,7 @@ class Fraction(Rational):
def __round__(self, ndigits: None = None) -> int: ...
@overload
def __round__(self, ndigits: int) -> Fraction: ...
def __hash__(self) -> int: ...
def __hash__(self) -> int: ... # type: ignore[override]
def __eq__(a, b: object) -> bool: ...
def __lt__(a, b: _ComparableNum) -> bool: ...
def __gt__(a, b: _ComparableNum) -> bool: ...

View File

@@ -416,6 +416,7 @@ class BoundArguments:
def __init__(self, signature: Signature, arguments: OrderedDict[str, Any]) -> None: ...
def apply_defaults(self) -> None: ...
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
#
# Classes and functions

View File

@@ -1,6 +1,6 @@
from _typeshed import Incomplete, StrPath
from collections.abc import Iterable, Iterator
from typing import IO, NoReturn, overload
from typing import IO, ClassVar, NoReturn, overload
from . import grammar
from .tokenize import _TokenInfo
@@ -46,5 +46,6 @@ class DFAState:
def addarc(self, next: DFAState, label: str) -> None: ...
def unifystate(self, old: DFAState, new: DFAState) -> None: ...
def __eq__(self, other: DFAState) -> bool: ... # type: ignore[override]
__hash__: ClassVar[None] # type: ignore[assignment]
def generate_grammar(filename: StrPath = "Grammar.txt") -> PgenGrammar: ...

View File

@@ -1,7 +1,7 @@
from _typeshed import Incomplete, SupportsGetItem, SupportsLenAndGetItem, Unused
from abc import abstractmethod
from collections.abc import Iterable, Iterator, MutableSequence
from typing import Final
from typing import ClassVar, Final
from typing_extensions import Self, TypeAlias
from .fixer_base import BaseFix
@@ -24,6 +24,7 @@ class Base:
was_changed: bool
was_checked: bool
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
@abstractmethod
def _eq(self, other: Base) -> bool: ...
@abstractmethod

View File

@@ -9,7 +9,7 @@
from _typeshed import Incomplete
from abc import ABCMeta, abstractmethod
from typing import Literal, Protocol, overload
from typing import ClassVar, Literal, Protocol, overload
__all__ = ["Number", "Complex", "Real", "Rational", "Integral"]
@@ -102,6 +102,7 @@ class Complex(Number, _ComplexLike):
def conjugate(self) -> _ComplexLike: ...
@abstractmethod
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
# See comment at the top of the file
# for why some of these return types are purposefully vague

View File

@@ -2,7 +2,7 @@ import builtins
from _typeshed import Incomplete, MaybeNone
from abc import abstractmethod
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import IO, Any, AnyStr, Literal, NoReturn, overload
from typing import IO, Any, AnyStr, ClassVar, Literal, NoReturn, overload
from typing_extensions import Self
__all__ = [
@@ -216,6 +216,7 @@ class Values:
def ensure_value(self, attr: str, value): ...
def read_file(self, filename: str, mode: str = "careful") -> None: ...
def read_module(self, modname: str, mode: str = "careful") -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
# __getattr__ doesn't exist, but anything passed as a default to __init__
# is set on the instance.
def __getattr__(self, name: str): ...

View File

@@ -1,7 +1,7 @@
from _typeshed import StrOrBytesPath
from collections.abc import Sequence
from types import CodeType
from typing import Any, final
from typing import Any, ClassVar, final
def expr(source: str) -> STType: ...
def suite(source: str) -> STType: ...
@@ -17,6 +17,7 @@ class ParserError(Exception): ...
@final
class STType:
__hash__: ClassVar[None] # type: ignore[assignment]
def compile(self, filename: StrOrBytesPath = ...) -> CodeType: ...
def isexpr(self) -> bool: ...
def issuite(self) -> bool: ...

View File

@@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer
from collections.abc import Mapping, MutableMapping
from datetime import datetime
from enum import Enum
from typing import IO, Any
from typing import IO, Any, ClassVar
from typing_extensions import Self
__all__ = ["InvalidFileException", "FMT_XML", "FMT_BINARY", "load", "dump", "loads", "dumps", "UID"]
@@ -100,6 +100,7 @@ if sys.version_info < (3, 9):
class Data:
data: bytes
def __init__(self, data: bytes) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
class UID:
data: int

View File

@@ -1,6 +1,6 @@
import sys
from collections.abc import Callable
from typing import Any, NamedTuple, type_check_only
from typing import Any, ClassVar, NamedTuple, type_check_only
from typing_extensions import TypeAlias
__all__ = ["scheduler"]
@@ -25,7 +25,8 @@ else:
argument: tuple[Any, ...]
kwargs: dict[str, Any]
class Event(_EventBase): ...
class Event(_EventBase):
__hash__: ClassVar[None] # type: ignore[assignment]
class scheduler:
timefunc: Callable[[], float]

View File

@@ -2,7 +2,7 @@ import sys
from _typeshed import FileDescriptorLike
from collections.abc import Iterable
from types import TracebackType
from typing import Any, final
from typing import Any, ClassVar, final
from typing_extensions import Self
if sys.platform != "win32":
@@ -53,6 +53,7 @@ if sys.platform != "linux" and sys.platform != "win32":
data: Any = ...,
udata: Any = ...,
) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
# BSD only
@final

View File

@@ -5,7 +5,7 @@ from collections.abc import Callable, Iterable, Mapping, Sequence
from tkinter.constants import *
from tkinter.font import _FontDescription
from types import TracebackType
from typing import Any, Generic, Literal, NamedTuple, Protocol, TypedDict, TypeVar, overload, type_check_only
from typing import Any, ClassVar, Generic, Literal, NamedTuple, Protocol, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias, TypeVarTuple, Unpack, deprecated
if sys.version_info >= (3, 11):
@@ -330,6 +330,7 @@ class Variable:
def trace_vinfo(self): ...
def __eq__(self, other: object) -> bool: ...
def __del__(self) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
class StringVar(Variable):
def __init__(self, master: Misc | None = None, value: str | None = None, name: str | None = None) -> None: ...

View File

@@ -58,6 +58,7 @@ class Font:
underline: bool = ...,
overstrike: bool = ...,
) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __setitem__(self, key: str, value: Any) -> None: ...
@overload
def cget(self, option: Literal["family"]) -> str: ...

View File

@@ -2,7 +2,7 @@ import sys
from _typeshed import SupportsWrite, Unused
from collections.abc import Generator, Iterable, Iterator, Mapping
from types import FrameType, TracebackType
from typing import Any, Literal, overload
from typing import Any, ClassVar, Literal, overload
from typing_extensions import Self, TypeAlias, deprecated
__all__ = [
@@ -229,6 +229,7 @@ class TracebackException:
) -> Self: ...
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
if sys.version_info >= (3, 11):
def format(self, *, chain: bool = True, _ctx: _ExceptionPrintContext | None = None) -> Generator[str, None, None]: ...
else:
@@ -292,6 +293,7 @@ class FrameSummary:
def __iter__(self) -> Iterator[Any]: ...
def __eq__(self, other: object) -> bool: ...
def __len__(self) -> Literal[4]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
class StackSummary(list[FrameSummary]):
@classmethod

View File

@@ -257,6 +257,7 @@ if sys.version_info >= (3, 10):
def __init__(self, origin: ParamSpec) -> None: ...
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
@final
class ParamSpecKwargs:
@@ -268,6 +269,7 @@ if sys.version_info >= (3, 10):
def __init__(self, origin: ParamSpec) -> None: ...
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
@final
class ParamSpec:

View File

@@ -2,7 +2,7 @@ import sys
from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, Sequence
from contextlib import _GeneratorContextManager
from types import TracebackType
from typing import Any, Final, Generic, Literal, TypeVar, overload
from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload
from typing_extensions import ParamSpec, Self, TypeAlias
_T = TypeVar("_T")
@@ -85,6 +85,7 @@ class _Call(tuple[Any, ...]):
two: bool = False,
from_kall: bool = True,
) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __eq__(self, other: object) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __call__(self, *args: Any, **kwargs: Any) -> _Call: ...
@@ -403,6 +404,7 @@ class MagicProxy(Base):
class _ANY:
def __eq__(self, other: object) -> Literal[True]: ...
def __ne__(self, other: object) -> Literal[False]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
ANY: Any

View File

@@ -1,6 +1,7 @@
import unittest.case
import unittest.result
from collections.abc import Iterable, Iterator
from typing import ClassVar
from typing_extensions import TypeAlias
_TestType: TypeAlias = unittest.case.TestCase | TestSuite
@@ -17,6 +18,7 @@ class BaseTestSuite:
def countTestCases(self) -> int: ...
def __iter__(self) -> Iterator[_TestType]: ...
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
class TestSuite(BaseTestSuite):
def run(self, result: unittest.result.TestResult, debug: bool = False) -> unittest.result.TestResult: ...

View File

@@ -3,7 +3,7 @@ from _typeshed import SupportsKeysAndGetItem
from _weakref import getweakrefcount as getweakrefcount, getweakrefs as getweakrefs, proxy as proxy
from _weakrefset import WeakSet as WeakSet
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping
from typing import Any, Generic, TypeVar, final, overload
from typing import Any, ClassVar, Generic, TypeVar, final, overload
from typing_extensions import ParamSpec, Self
if sys.version_info >= (3, 9):
@@ -47,11 +47,13 @@ class CallableProxyType(Generic[_CallableT]): # "weakcallableproxy"
def __eq__(self, value: object, /) -> bool: ...
def __getattr__(self, attr: str) -> Any: ...
__call__: _CallableT
__hash__: ClassVar[None] # type: ignore[assignment]
@final
class ProxyType(Generic[_T]): # "weakproxy"
def __eq__(self, value: object, /) -> bool: ...
def __getattr__(self, attr: str) -> Any: ...
__hash__: ClassVar[None] # type: ignore[assignment]
class ReferenceType(Generic[_T]): # "weakref"
__callback__: Callable[[Self], Any]

View File

@@ -1,7 +1,7 @@
import sys
import xml.dom
from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite
from typing import Literal, NoReturn, TypeVar, overload
from typing import ClassVar, Literal, NoReturn, TypeVar, overload
from typing_extensions import Self
from xml.dom.minicompat import NodeList
from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS
@@ -151,6 +151,7 @@ class NamedNodeMap:
def keysNS(self): ...
def values(self): ...
def get(self, name: str, value: Incomplete | None = None): ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __len__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: NamedNodeMap) -> bool: ...

View File

@@ -6,7 +6,7 @@ from collections.abc import Callable, Iterable, Mapping
from datetime import datetime
from io import BytesIO
from types import TracebackType
from typing import Any, Final, Literal, Protocol, overload
from typing import Any, ClassVar, Final, Literal, Protocol, overload
from typing_extensions import Self, TypeAlias
class _SupportsTimeTuple(Protocol):
@@ -76,6 +76,7 @@ def _strftime(value: _XMLDate) -> str: ... # undocumented
class DateTime:
value: str # undocumented
def __init__(self, value: int | str | datetime | time.struct_time | tuple[int, ...] = 0) -> None: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __lt__(self, other: _DateTimeComparable) -> bool: ...
def __le__(self, other: _DateTimeComparable) -> bool: ...
def __gt__(self, other: _DateTimeComparable) -> bool: ...
@@ -95,6 +96,7 @@ class Binary:
def decode(self, data: ReadableBuffer) -> None: ...
def encode(self, out: SupportsWrite[str]) -> None: ...
def __eq__(self, other: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def _binary(data: ReadableBuffer) -> Binary: ... # undocumented

View File

@@ -1,5 +1,5 @@
import sys
from typing import Any, final
from typing import Any, ClassVar, final
class Str(str): ...
@@ -17,6 +17,8 @@ if sys.version_info >= (3, 10):
else:
class error(Exception): ...
class Null: ...
class Null:
__hash__: ClassVar[None] # type: ignore[assignment]
def roj(b: Any, /) -> None: ...

View File

@@ -31,7 +31,7 @@ class StyleArray(array[int]):
xfId: ArrayDescriptor[int]
def __new__(cls, args: bytes | bytearray | Iterable[int] = [0, 0, 0, 0, 0, 0, 0, 0, 0]) -> Self: ...
def __init__(self, args: bytes | bytearray | Iterable[int] = [0, 0, 0, 0, 0, 0, 0, 0, 0]) -> None: ...
def __hash__(self) -> int: ...
def __hash__(self) -> int: ... # type: ignore[override]
def __copy__(self) -> StyleArray: ...
def __deepcopy__(self, memo: Unused) -> StyleArray: ...