Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix attrs hashability detection when inheriting from mutable#17012

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@Tinche
Copy link
Contributor

Frozenattrs classes inheriting from mutable classes are hashable; fix this case and add a test.

Also support frozen classes withhash=False (although I'm not sure this is a common use case at all, but it was easy to add).

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@TincheTincheforce-pushed thetin/fix-attrs-frozen-hashability branch from633db11 to45454efCompareMarch 11, 2024 19:48
@Tinche
Copy link
ContributorAuthor

@sobolevn Ready for review, if you have time!

@github-actions
Copy link
Contributor

According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Hnasar pushed a commit to Hnasar/mypy that referenced this pull requestMar 11, 2024
This commit fixes a couple regressions in 1.9.0 from91be285.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-L1689Mypy 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`.Fixespython#17015Fixespython#16556 (comment)Based on a patch inpython#17012Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>
Hnasar added a commit to Hnasar/mypy that referenced this pull requestMar 11, 2024
This commit fixes a couple regressions in 1.9.0 from91be285.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-L1689Mypy 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`.Fixespython#17015Fixespython#16556 (comment)Based on a patch inpython#17012Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>
Hnasar added a commit to Hnasar/mypy that referenced this pull requestMar 11, 2024
This commit fixes a couple regressions in 1.9.0 from91be285.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-L1689Mypy 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`.Fixespython#17015Fixespython#16556 (comment)Based on a patch inpython#17012Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>
Hnasar added a commit to Hnasar/mypy that referenced this pull requestMar 11, 2024
This commit fixes a couple regressions in 1.9.0 from91be285.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-L1689Mypy 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`.Fixespython#17015Fixespython#16556 (comment)Based on a patch inpython#17012Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>
Hnasar added a commit to Hnasar/mypy that referenced this pull requestMar 11, 2024
This commit fixes a couple regressions in 1.9.0 from91be285.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-L1689Mypy 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`.Fixespython#17015Fixespython#16556 (comment)Based on a patch inpython#17012Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>
@Hnasar
Copy link
Contributor

Thanks for the quick fix@Tinche ! I was curious to learn myself how attrs handles this, so I ended up cloning your fix and testing it out, but realized that the logic didn't always accurately match attrs'. And also it didn't fix the regression I reported in#17015. So I reworked some of the subtle issues with this patch and added several other test cases here#17016

Hnasar added a commit to Hnasar/mypy that referenced this pull requestMar 12, 2024
This commit fixes a couple regressions in 1.9.0 from91be285.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-L1689Mypy 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`.Fixespython#17015Fixespython#16556 (comment)Based on a patch inpython#17012Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>
@sobolevn
Copy link
Member

@Tinche can you please first decide which PR should be reviewed? :)

@Tinche
Copy link
ContributorAuthor

@Hnasar Good job! Let's use yours since it's more comprehensive. cc@sobolevn

Hnasar reacted with heart emoji

@TincheTinche closed thisMar 12, 2024
JukkaL pushed a commit that referenced this pull requestMar 15, 2024
This commit fixes a couple regressions in 1.9.0 from91be285.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-L1689Mypy 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#17015Fixes#16556 (comment)Based on a patch in#17012Co-Authored-By: Tin Tvrtkovic <tinchester@gmail.com>Co-authored-by: Hashem Nasarat <hashem@hudson-trading.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@Tinche@Hnasar@sobolevn

[8]ページ先頭

©2009-2025 Movatter.jp