Uh oh!
There was an error while loading. Please reload this page.
Adds __hash__ method to @dataclasses.dataclass, refs #11463 - #11496
Adds __hash__ method to @dataclasses.dataclass, refs #11463#11496sobolevn wants to merge 10 commits into
__hash__ method to @dataclasses.dataclass, refs #11463#11496Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
JukkaL
left a comment
There was a problem hiding this comment.
Thanks for the PR! I like that all the possible cases are carefully tested. Left some minor comments, overall looks good.
Uh oh!
There was an error while loading. Please reload this page.
| unsafe_hash = decorator_arguments.get('unsafe_hash', False) | ||
| eq = decorator_arguments['eq'] | ||
| frozen = decorator_arguments['frozen'] | ||
| cond = (unsafe_hash, eq, frozen) |
There was a problem hiding this comment.
I think that this makes the conditions harder to understand. If you think that the conditions would be too verbose otherwise, maybe instead rename unsafe_hash to something shorter, such as unsafe. Now you could write something like if not unsafe and eq and not frozen.
There was a problem hiding this comment.
if ((notunsafe_hashandnoteqandnotfrozen)
or (notunsafe_hashandnoteqandfrozen)):I think that both are quite hard to read 😞
Mine was inspired by pattern matching technique I use in different functional languages.
Anyways, I've changed it! 👍
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
JukkaL
commented
Dec 13, 2021
The mypy_primer failure seems to indicate a real issue. For example, this generates a false positive: fromdataclassesimportdataclassa=f() # Forward ref to force two semantic analysis passes@dataclass(unsafe_hash=True)classC: # Cannot overwrite attribute "__hash__" in class "C"x: strdeff(): passIt looks like the new logic doesn't work correctly if we need multiple semantic analysis passes. If the previous pass had added a |
sobolevn
commented
Dec 14, 2021
Let's try this solution. Now I check that given variable was not plugin generated. |
JukkaL
commented
Feb 22, 2022
Can you fix the conflicts? I can do another round of review once the PR is up-to-date. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sobolevn
commented
Jul 19, 2022
I somehow nuked my old fork and that's why all my old PRs are now closed. I can recreate some of them. Here's a list of things I still want to get merged:
|
AlexWaygood
commented
Jul 19, 2022
I was a big fan of these, as well :) |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Closes#11463
Closes#11495
I still need to add a test case for
3.9, where there's nounsafe_hasharg, but__hash__is still added somehow.Right now I just want to see the CI results.