mypy
mypy copied to clipboard
Non-hashable tuple should not be accepted as `Hashable`
Bug Report
I'd expect to get a type error when trying to pass a tuple to a Hashable bound if that tuple contains any non-hashable element type.
To Reproduce
from typing import Hashable, TypeVar
T = TypeVar("T", bound=Hashable)
def f(x: T) -> T:
print(hash(x))
return x
def usage1(x: tuple[dict[str, str], ...]):
f(x)
def usage2(x: tuple[dict[str, str], int, int]):
f(x)
def usage3(x: tuple[int, int, dict[str, str]]):
f(x)
Expected Behavior
Type error in all f(x) lines, rejecting the non-hashable type.
Actual Behavior
The type check passes despite the unsound typing.
Your Environment
- Mypy version used: 1.16.0
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.12