diff --git a/pandas/core/arrays/arrow/_arrow_utils.py b/pandas/core/arrays/arrow/_arrow_utils.py index 5ed10661e8983..3b8333fdb410a 100644 --- a/pandas/core/arrays/arrow/_arrow_utils.py +++ b/pandas/core/arrays/arrow/_arrow_utils.py @@ -92,7 +92,7 @@ def __eq__(self, other): else: return NotImplemented - def __hash__(self): + def __hash__(self) -> int: return hash((str(self), self.freq)) def to_pandas_dtype(self): @@ -158,7 +158,7 @@ def __eq__(self, other): else: return NotImplemented - def __hash__(self): + def __hash__(self) -> int: return hash((str(self), str(self.subtype), self.inclusive)) def to_pandas_dtype(self): diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 882cc76cf2d77..6c9b7adadb7b0 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -14,6 +14,7 @@ TYPE_CHECKING, Any, Callable, + ClassVar, Iterator, Literal, Sequence, @@ -1442,7 +1443,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs): # https://github.com/python/typeshed/issues/2148#issuecomment-520783318 # Incompatible types in assignment (expression has type "None", base class # "object" defined the type as "Callable[[object], int]") - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] # ------------------------------------------------------------------------ # Non-Optimized Default Methods; in the case of the private methods here, diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index 859995cb3c230..eaed6257736ba 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -99,7 +99,7 @@ def __init__(self, dtype: Dtype = np.float64, fill_value: Any = None) -> None: self._fill_value = fill_value self._check_fill_value() - def __hash__(self): + def __hash__(self) -> int: # Python3 doesn't inherit __hash__ when a base class overrides # __eq__, so we explicitly do it here. return super().__hash__() diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bd8e04df7594f..e392802bdb5ea 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -13,6 +13,7 @@ TYPE_CHECKING, Any, Callable, + ClassVar, Hashable, Literal, Mapping, @@ -1882,7 +1883,7 @@ def _drop_labels_or_levels(self, keys, axis: int = 0): # https://github.com/python/typeshed/issues/2148#issuecomment-520783318 # Incompatible types in assignment (expression has type "None", base class # "object" defined the type as "Callable[[object], int]") - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] def __iter__(self): """ diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 667ce4664c359..fc5fcaeab7d2a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -8,6 +8,7 @@ TYPE_CHECKING, Any, Callable, + ClassVar, Hashable, Iterable, Literal, @@ -5296,7 +5297,7 @@ def __contains__(self, key: Any) -> bool: # https://github.com/python/typeshed/issues/2148#issuecomment-520783318 # Incompatible types in assignment (expression has type "None", base class # "object" defined the type as "Callable[[object], int]") - __hash__: None # type: ignore[assignment] + __hash__: ClassVar[None] # type: ignore[assignment] @final def __setitem__(self, key, value): diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index ed5cf047ab59f..deb6ac2c80a81 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -89,7 +89,8 @@ def __mul__(self, other): def __reduce__(self): return type(self), (list(self),) - def __hash__(self): + # error: Signature of "__hash__" incompatible with supertype "list" + def __hash__(self) -> int: # type: ignore[override] return hash(tuple(self)) def _disabled(self, *args, **kwargs):