diff --git a/stdlib/@tests/test_cases/builtins/check_tuple.py b/stdlib/@tests/test_cases/builtins/check_tuple.py index bc0d8db28389..5c1f2e7ca8d5 100644 --- a/stdlib/@tests/test_cases/builtins/check_tuple.py +++ b/stdlib/@tests/test_cases/builtins/check_tuple.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Tuple +import sys +from typing import Any, Dict, Tuple from typing_extensions import assert_type @@ -11,3 +12,19 @@ class TupleSub(Tuple[int, ...]): assert_type(TupleSub(), TupleSub) assert_type(TupleSub([1, 2, 3]), TupleSub) + +# Hashability shenanigans, see #15852 +t: Tuple[int, int] = (1, 3) +hash(t) +u: Tuple[int, ...] = tuple(b"spam") +hash(u) +v: Tuple[str] = ("",) +hash(v) +w: Tuple[()] = () +hash(w) +hash(tuple(sys.platform)) +hash(([],)) # type: ignore +x: Tuple[Any, Any] = ((), ()) +hash(x) +z: Tuple[Tuple[Any, ...], Dict[str, Any]] = ((), {}) +hash(z) # type: ignore diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 096d440ac38c..df1b4dc7091b 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -30,7 +30,7 @@ from _typeshed import ( SupportsRichComparisonT, SupportsWrite, ) -from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized +from collections.abc import Awaitable, Callable, Hashable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper from os import PathLike from types import CellType, CodeType, EllipsisType, GenericAlias, NotImplementedType, TracebackType, UnionType @@ -1152,7 +1152,7 @@ class tuple(Sequence[_T_co]): def __gt__(self, value: tuple[_T_co, ...], /) -> bool: ... def __ge__(self, value: tuple[_T_co, ...], /) -> bool: ... def __eq__(self, value: object, /) -> bool: ... - def __hash__(self) -> int: ... + def __hash__(self: tuple[Hashable, ...]) -> int: ... @overload def __add__(self, value: tuple[_T_co, ...], /) -> tuple[_T_co, ...]: ...