diff --git a/stdlib/@tests/test_cases/builtins/check_tuple.py b/stdlib/@tests/test_cases/builtins/check_tuple.py index bc0d8db28389..ac9633135997 100644 --- a/stdlib/@tests/test_cases/builtins/check_tuple.py +++ b/stdlib/@tests/test_cases/builtins/check_tuple.py @@ -1,13 +1,27 @@ from __future__ import annotations -from typing import Tuple +import sys +from typing import Any from typing_extensions import assert_type # Empty tuples, see #8275 -class TupleSub(Tuple[int, ...]): +class TupleSub(tuple[int, ...]): pass 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)) +x: tuple[Any, Any] = ((), ()) +hash(x) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 9c8394ced492..89ddc36ec1a8 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, Set as AbstractSet, Sized +from collections.abc import Awaitable, Callable, Hashable, Iterable, Iterator, MutableSet, 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 @@ -1163,7 +1163,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, ...]: ...