Stdlib: add many missing __hash__
and __eq__
methods
#10464
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pyright has recently been trying to add some sophisticated understanding of how hashability works at runtime. Namely, if a class overrides
__eq__
at runtime but doesn't override__hash__
, the runtime views instances of the class as unhashable: if you override__eq__
, you also have to explicitly override__hash__
as well if you want instances to be hashable. However, pyright is currently unable to implement its new feature, because of the fact that many classes in the stdlib override__hash__
at runtime, but don't currently include__hash__
in typeshed's stubs: microsoft/pyright#5513. Let's fix that.I also added many missing
__eq__
methods. As well as their relevance to hashability, these are also used as a heuristic for mypy's overlapping-equality check. Like with__hash__
, therefore, it's important to include these in the stub even if the signature on a subclass is the same as on a superclass.I found all these with the following stubtest patch:
Cc. @TheTripleV