8000 Generate dataclasses `__hash__` according to runtime semantics by sterliakov · Pull Request #19043 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Generate dataclasses __hash__ according to runtime semantics #19043

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ignore object.__hash__ as we do everywhere else
  • Loading branch information
sterliakov committed May 6, 2025
commit 7d7045942ae95891f3d3ec00078f1915f18532fb
4 changes: 2 additions & 2 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ def _add_dunder_hash(self, is_hashable: bool) -> None:
else:
# Python sets `__hash__ = None` otherwise, do the same.
parent_method = self._cls.info.get_method("__hash__")
if parent_method is not None:
# If we inherited `__hash__`, ensure it isn't overridden
if parent_method is not None and parent_method.info.fullname != "builtins.object":
# If we inherited `__hash__` not from `object`, ensure it isn't overridden
self._api.fail(
"Incompatible override of '__hash__': dataclasses without"
" 'frozen' or 'unsafe_hash' have '__hash__' set to None",
Expand Down
0