Skip to content

Non-hashable tuple should not be accepted as Hashable #19232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bluenote10 opened this issue Jun 4, 2025 · 0 comments
Open

Non-hashable tuple should not be accepted as Hashable #19232

bluenote10 opened this issue Jun 4, 2025 · 0 comments
Labels
bug mypy got something wrong

Comments

@bluenote10
Copy link
Contributor

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
@bluenote10 bluenote10 added the bug mypy got something wrong label Jun 4, 2025
@bluenote10 bluenote10 changed the title Non-hashable tuple should be accepted as Hashable Non-hashable tuple should not be accepted as Hashable Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant