Skip to content
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

no error when unhashable object in dict #11465

Open
KotlinIsland opened this issue Nov 5, 2021 · 2 comments
Open

no error when unhashable object in dict #11465

KotlinIsland opened this issue Nov 5, 2021 · 2 comments
Labels
feature topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@KotlinIsland
Copy link
Contributor

from typing import Hashable


class SomeDClass:
    __hash__: None = None  # type: ignore

d = {
    [1]: 1,  # SUS ALERT! fails at runtime
    SomeDClass(): 2,  # SUS ALERT! fails at runtime
}

Is this an issue with the stubs?

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Nov 5, 2021
@KotlinIsland
Copy link
Contributor Author

python/typeshed#3884

@srittau
Copy link
Contributor

srittau commented Nov 5, 2021

I believe, type checkers should special case __hash__: None to be valid, no matter what the stubs say. After all, object.__hash__() has some weird rules around it that can't be represented in the stubs. Writing __hash__: None in stubs is the current way to signal that a class is not hashable and requires a # type: ignore currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

3 participants