-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
__hash__ = None
generates an error
#4266
Comments
Is this a regression? Have you tried it with earlier versions? Or are you just mentioning 0.550 to indicate you're up to date? |
I hadn't tried earlier versions - just indicating that I'm up-to-date. I've now tested with 0.521, 0.530 and 0.540 and get the same behaviour - so it's not a regression, or at least not a recent one. |
Doesn't |
Sure, that suppresses the error, but it seems like mypy (or possibly typeshed) has the wrong model of Should I file this against typeshed instead? |
No, this is not the wrong idea. Hashability is optional by convention, but as far as substitutability goes, once you define def f(x: object) -> Dict[object, int]: # return type is valid
return {x: 5} # must be valid This is especially true when The fact that hashability is optional seems to work pretty well with you declaring not to subtype |
If you're happy that mypy is working as designed then you can close this. However, it seems like
fails to identify that |
So the issue is about making mypy not forget that the class is unhashable in the presence of It will not be bullet-proof unless we'll make x: object = Foo()
print_hash(x) # mypy cannot complain here |
Just FYI on current master |
This is needed to allow python/typeshed#2221 |
A class that does not declare a base implicitly inherits from
|
(The key request here is formulated in @elazarg's comment above: #4266 (comment)) |
It isn't necessary to set You can see from this that class A:
def __eq__(self, other):
return False
print(A.__hash__) |
__hash__ = None
fails in strict-optional mode__hash__ = None
generates an error
In mypy 0.550 with
--strict-optional
, defining an unhashable class like so:gives
The text was updated successfully, but these errors were encountered: