-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
str
not detected as Hashable
#8293
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
Comments
This due to invariance; see https://mypy.readthedocs.io/en/latest/common_issues.html#invariance-vs-covariance. (Although |
Is there a solution to this aside from just ignoring the type check though? Every str should be Hashable, so why doesn't this work? |
@jamesmcm -- mypy is reporting a legitimate issue with the above code. Basically, it would be legal for The docs linked above discuss this problem and some workarounds. The quickest one for the above example would be to switch to having Or to rephrase, having the data structure be read-only/disallowing |
@Michael0x2a Mapping is actually also invariant in the key type, see https://github.com/python/typeshed/blob/master/stdlib/3/typing.pyi#L400. |
This is probably a duplicate of #1746 - but I don't see a resolution
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
test.py:7: error: Argument 1 to "foo" has incompatible type "Dict[str, int]"; expected "Dict[Hashable, int]"
Success: no issues found in 1 source file
Do you see the same issue after installing mypy from Git master?
mypy 0.761
None
the full traceback below.
(You can freely edit this text, please remove all the lines
you believe are unnecessary.)
The text was updated successfully, but these errors were encountered: