-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Remove un-needed __hash__
methods from stdlib
#8465
Conversation
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, although I'd like another maintainer to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too, but I'd like to get @JelleZijlstra's feedback. I think he had some Thoughts when I tried to do something along these lines a while back with some other methods.
@JelleZijlstra frienly ping 🙂 |
While working on stubs for
django
I've noticed that sometimes people redefine__hash__
.But, this is not what we do for other methods. For example, if base class
A
definesfoo
, its child classB
does not need to also definefoo
. Parent's definition will be used by default. We only annotate redefinitions.So,
__hash__
is defined inobject
. Child classes may not redefine it, unless:__hash__
returns something different, notint
(likeenum.Enum
does right now)__hash__
is set to beClassVar[None]
__hash__
is reset after parent'sClassVar[None]
to indicate that subclass is immutable again__hash__
is required to be set explicitly as a part of@abstractmethod
parent's def, likenumbers.Number
doesMypy sample: https://mypy-play.net/?mypy=latest&python=3.10&gist=cef2a15be8adfa8d646d260232e6b38a
What do others think?