attrs: Fix emulating hash method logic#17016
Merged
JukkaL merged 2 commits intopython:masterfrom Mar 15, 2024
Merged
Conversation
This commit fixes a couple regressions in 1.9.0 from 91be285. Attrs' logic for hashability is slightly complex: * https://www.attrs.org/en/stable/hashing.html * https://github.com/python-attrs/attrs/blob/9e443b18527dc96b194e92805fa751cbf8434ba9/src/attr/_make.py#L1660-L1689 Mypy now properly emulates attrs' logic so that custom `__hash__` implementations are preserved, `@frozen` subclasses are always hashable, and classes are only made unhashable based on the values of `eq` and `unsafe_hash`. Fixes python#17015 Fixes python#16556 (comment) Based on a patch in python#17012 Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>
a663346 to
d40909e
Compare
Add another test for parameter precedence
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
JukkaL
approved these changes
Mar 15, 2024
Collaborator
JukkaL
left a comment
There was a problem hiding this comment.
Thanks for the PR! I checked that the new test cases match runtime behavior.
Contributor
|
Great job @Hnasar ! |
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.
This commit fixes a couple regressions in 1.9.0 from 91be285.
Attrs' logic for hashability is slightly complex:
Mypy now properly emulates attrs' logic so that custom
__hash__implementations are preserved,@frozensubclasses are always hashable, and classes are only made unhashable based on the values ofeqandunsafe_hash.Fixes #17015
Fixes #16556 (comment)
Based on a patch in #17012
Co-Authored-By: Tin Tvrtkovic tinchester@gmail.com