10000 Handle `__hash__ = None` in somewhat more intuitive fashion by sterliakov · Pull Request #19168 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Handle __hash__ = None in somewhat more intuitive fashion #19168

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
Missing get_proper_type
  • Loading branch information
sterliakov committed May 29, 2025
commit a17a313592fd82baaf3c8dde8745f9fce87c8a5d
8 changes: 4 additions & 4 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2215,10 +2215,6 @@ def check_method_override_for_base_with_name(
# Will always fail to typecheck below, since we know the node is a method
original_type = NoneType()

if name == "__hash__" and isinstance(original_type, NoneType):
# Allow defining `__hash__` even if parent class was explicitly made unhashable
return False

always_allow_covariant = False
if is_settable_property(defn) and (
is_settable_property(original_node) or isinstance(original_node, Var)
Expand All @@ -2242,6 +2238,10 @@ def check_method_override_for_base_with_name(
typ = get_proper_type(typ)
original_type = get_proper_type(original_type)

if name == "__hash__" and isinstance(original_type, NoneType):
# Allow defining `__hash__` even if parent class was explicitly made unhashable
return False

if (
is_property(defn)
and isinstance(original_node, Var)
Expand Down
Loading
0