Skip to content

Commit efb4af0

Browse files
authored
Mark some types as non-hashable (#3219)
Based on @JelleZijlstra's PR #2221. Fixes #2148
1 parent 1d21315 commit efb4af0

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ class bytearray(MutableSequence[int], ByteString):
734734
def __repr__(self) -> str: ...
735735
def __int__(self) -> int: ...
736736
def __float__(self) -> float: ...
737-
def __hash__(self) -> int: ...
737+
__hash__: None # type: ignore
738738
@overload
739739
def __getitem__(self, i: int) -> int: ...
740740
@overload
@@ -849,6 +849,7 @@ class slice(object):
849849
def __init__(self, stop: Any) -> None: ...
850850
@overload
851851
def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ...
852+
__hash__: None # type: ignore
852853
def indices(self, len: int) -> Tuple[int, int, int]: ...
853854

854855
class tuple(Sequence[_T_co], Generic[_T_co]):
@@ -906,7 +907,7 @@ class list(MutableSequence[_T], Generic[_T]):
906907
def __len__(self) -> int: ...
907908
def __iter__(self) -> Iterator[_T]: ...
908909
def __str__(self) -> str: ...
909-
def __hash__(self) -> int: ...
910+
__hash__: None # type: ignore
910911
@overload
911912
def __getitem__(self, i: int) -> _T: ...
912913
@overload
@@ -980,6 +981,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
980981
def __delitem__(self, v: _KT) -> None: ...
981982
def __iter__(self) -> Iterator[_KT]: ...
982983
def __str__(self) -> str: ...
984+
__hash__: None # type: ignore
983985

984986
class set(MutableSet[_T], Generic[_T]):
985987
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...
@@ -1016,6 +1018,7 @@ class set(MutableSet[_T], Generic[_T]):
10161018
def __lt__(self, s: AbstractSet[object]) -> bool: ...
10171019
def __ge__(self, s: AbstractSet[object]) -> bool: ...
10181020
def __gt__(self, s: AbstractSet[object]) -> bool: ...
1021+
__hash__: None # type: ignore
10191022

10201023
class frozenset(AbstractSet[_T], Generic[_T]):
10211024
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...

stdlib/2and3/builtins.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ class bytearray(MutableSequence[int], ByteString):
734734
def __repr__(self) -> str: ...
735735
def __int__(self) -> int: ...
736736
def __float__(self) -> float: ...
737-
def __hash__(self) -> int: ...
737+
__hash__: None # type: ignore
738738
@overload
739739
def __getitem__(self, i: int) -> int: ...
740740
@overload
@@ -849,6 +849,7 @@ class slice(object):
849849
def __init__(self, stop: Any) -> None: ...
850850
@overload
851851
def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ...
852+
__hash__: None # type: ignore
852853
def indices(self, len: int) -> Tuple[int, int, int]: ...
853854

854855
class tuple(Sequence[_T_co], Generic[_T_co]):
@@ -906,7 +907,7 @@ class list(MutableSequence[_T], Generic[_T]):
906907
def __len__(self) -> int: ...
907908
def __iter__(self) -> Iterator[_T]: ...
908909
def __str__(self) -> str: ...
909-
def __hash__(self) -> int: ...
910+
__hash__: None # type: ignore
910911
@overload
911912
def __getitem__(self, i: int) -> _T: ...
912913
@overload
@@ -980,6 +981,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
980981
def __delitem__(self, v: _KT) -> None: ...
981982
def __iter__(self) -> Iterator[_KT]: ...
982983
def __str__(self) -> str: ...
984+
__hash__: None # type: ignore
983985

984986
class set(MutableSet[_T], Generic[_T]):
985987
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...
@@ -1016,6 +1018,7 @@ class set(MutableSet[_T], Generic[_T]):
10161018
def __lt__(self, s: AbstractSet[object]) -> bool: ...
10171019
def __ge__(self, s: AbstractSet[object]) -> bool: ...
10181020
def __gt__(self, s: AbstractSet[object]) -> bool: ...
1021+
__hash__: None # type: ignore
10191022

10201023
class frozenset(AbstractSet[_T], Generic[_T]):
10211024
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...

third_party/2and3/werkzeug/datastructures.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def is_immutable(self): ...
1111
def iter_multi_items(mapping): ...
1212
def native_itermethods(names): ...
1313

14-
class ImmutableListMixin:
15-
def __hash__(self): ...
14+
class ImmutableListMixin(object):
15+
def __hash__(self) -> int: ...
1616
def __reduce_ex__(self, protocol): ...
1717
def __delitem__(self, key): ...
1818
def __delslice__(self, i, j): ...
@@ -28,13 +28,13 @@ class ImmutableListMixin:
2828
def reverse(self): ...
2929
def sort(self, cmp: Optional[Any] = ..., key: Optional[Any] = ..., reverse: Optional[Any] = ...): ...
3030

31-
class ImmutableList(ImmutableListMixin, list): ...
31+
class ImmutableList(ImmutableListMixin, list): ... # type: ignore
3232

33-
class ImmutableDictMixin:
33+
class ImmutableDictMixin(object):
3434
@classmethod
3535
def fromkeys(cls, *args, **kwargs): ...
3636
def __reduce_ex__(self, protocol): ...
37-
def __hash__(self): ...
37+
def __hash__(self) -> int: ...
3838
def setdefault(self, key, default: Optional[Any] = ...): ...
3939
def update(self, *args, **kwargs): ...
4040
def pop(self, key, default: Optional[Any] = ...): ...
@@ -71,7 +71,7 @@ class TypeConversionDict(Dict[_K, _V]):
7171
@overload
7272
def get(self, key: _K, default: _D, type: Callable[[_V], _R]) -> Union[_R, _D]: ...
7373

74-
class ImmutableTypeConversionDict(ImmutableDictMixin, TypeConversionDict[_K, _V]):
74+
class ImmutableTypeConversionDict(ImmutableDictMixin, TypeConversionDict[_K, _V]): # type: ignore
7575
def copy(self) -> TypeConversionDict[_K, _V]: ...
7676
def __copy__(self) -> ImmutableTypeConversionDict[_K, _V]: ...
7777

@@ -207,7 +207,7 @@ class EnvironHeaders(ImmutableHeadersMixin, Headers):
207207
def __iter__(self): ...
208208
def copy(self): ...
209209

210-
class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict):
210+
class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict): # type: ignore
211211
def __reduce_ex__(self, protocol): ...
212212
dicts: Any
213213
def __init__(self, dicts: Optional[Any] = ...): ...
@@ -231,15 +231,15 @@ class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict):
231231
class FileMultiDict(MultiDict):
232232
def add_file(self, name, file, filename: Optional[Any] = ..., content_type: Optional[Any] = ...): ...
233233

234-
class ImmutableDict(ImmutableDictMixin, dict):
234+
class ImmutableDict(ImmutableDictMixin, dict): # type: ignore
235235
def copy(self): ...
236236
def __copy__(self): ...
237237

238-
class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict):
238+
class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict): # type: ignore
239239
def copy(self): ...
240240
def __copy__(self): ...
241241

242-
class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict):
242+
class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict): # type: ignore
243243
def copy(self): ...
244244
def __copy__(self): ...
245245

@@ -280,7 +280,7 @@ class _CacheControl(UpdateDictMixin, dict):
280280
def __init__(self, values=..., on_update: Optional[Any] = ...): ...
281281
def to_header(self): ...
282282

283-
class RequestCacheControl(ImmutableDictMixin, _CacheControl):
283+
class RequestCacheControl(ImmutableDictMixin, _CacheControl): # type: ignore
284284
max_stale: Any
285285
min_fresh: Any
286286
no_transform: Any
@@ -360,7 +360,7 @@ class ContentRange:
360360
def __nonzero__(self): ...
361361
__bool__: Any
362362

363-
class Authorization(ImmutableDictMixin, Dict[str, Any]):
363+
class Authorization(ImmutableDictMixin, Dict[str, Any]): # type: ignore
364364
type: str
365365
def __init__(self, auth_type: str, data: Optional[Mapping[str, Any]] = ...) -> None: ...
366366
@property

0 commit comments

Comments
 (0)