Repository navigation
Stdlib: add many missing __hash__ and __eq__ methods - #10464
Merged
Merged
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/elements/date_input_test.py: note: In member "test_range_session_state" of class "DateInputTest":
- lib/tests/streamlit/elements/date_input_test.py:174:16: error: Non-overlapping equality check (left operand type: "Union[date, Tuple[], Tuple[date], Tuple[date, date]]", right operand type: "List[datetime]") [comparison-overlap]
|
srittau
approved these changes
Jul 17, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Details
Cc. @TheTripleV