33"""
44
55from dataclasses import dataclass
6- from typing import Hashable , assert_type
6+ from typing import Callable , Hashable , assert_type
77
88
99@dataclass
@@ -23,11 +23,7 @@ class DC2:
2323 a : int
2424
2525
26- # Because `DC2` is frozen, type checkers should synthesize
27- # a callable `__hash__` method for it, and therefore should
28- # emit a diagnostic here:
29- assert_type (DC2 .__hash__ , None ) # E
30-
26+ dc2_hash : Callable [..., int ] = DC2 .__hash__ # OK
3127DC2 (0 ).__hash__ () # OK
3228v2 : Hashable = DC2 (0 ) # OK
3329
@@ -49,11 +45,7 @@ class DC4:
4945 a : int
5046
5147
52- # Because `DC4` is frozen, type checkers should synthesize
53- # a callable `__hash__` method for it, and therefore should
54- # emit a diagnostic here:
55- assert_type (DC4 .__hash__ , None ) # E
56-
48+ dc4_hash : Callable [..., int ] = DC4 .__hash__ # OK
5749DC4 (0 ).__hash__ () # OK
5850v4 : Hashable = DC4 (0 ) # OK
5951
@@ -63,11 +55,7 @@ class DC5:
6355 a : int
6456
6557
66- # Type checkers should synthesize a callable `__hash__`
67- # method for `DC5` due to `unsafe_hash=True`, and therefore
68- # should emit a diagnostic here:
69- assert_type (DC5 .__hash__ , None ) # E
70-
58+ dc5_hash : Callable [..., int ] = DC5 .__hash__ # OK
7159DC5 (0 ).__hash__ () # OK
7260v5 : Hashable = DC5 (0 ) # OK
7361
@@ -80,10 +68,7 @@ def __hash__(self) -> int:
8068 return 0
8169
8270
83- # Type checkers should respect the manually defined `__hash__`
84- # method for `DC6`, and therefore should emit a diagnostic here:
85- assert_type (DC6 .__hash__ , None ) # E
86-
71+ dc6_hash : Callable [..., int ] = DC6 .__hash__ # OK
8772DC6 (0 ).__hash__ () # OK
8873v6 : Hashable = DC6 (0 ) # OK
8974
@@ -96,10 +81,6 @@ def __eq__(self, other) -> bool:
9681 return self .a == other .a
9782
9883
99- # Because `DC7` is frozen, type checkers should synthesize
100- # a callable `__hash__` method for it, and therefore should
101- # emit a diagnostic here:
102- assert_type (DC7 .__hash__ , None ) # E
103-
84+ dc7_hash : Callable [..., int ] = DC7 .__hash__ # OK
10485DC7 (0 ).__hash__ () # OK
10586v7 : Hashable = DC7 (0 ) # OK
0 commit comments