2Tests the synthesis of the __hash__ method in a dataclass.
5from dataclasses import dataclass
6from typing import Callable, Hashable, assert_type
14assert_type(DC1.__hash__, None)
16# These should generate errors because DC1 isn't hashable.
[call-non-callable] Object of type `None` is not callable
18v1: Hashable = DC1(0) # E
Expected a ty diagnostic for this line
21@dataclass(eq=True, frozen=True)
26dc2_hash: Callable[..., int] = DC2.__hash__ # OK
28v2: Hashable = DC2(0) # OK
36assert_type(DC3.__hash__, None)
38# These should generate errors because DC3 isn't hashable.
[call-non-callable] Object of type `None` is not callable
40v3: Hashable = DC3(0) # E
Expected a ty diagnostic for this line
43@dataclass(frozen=True)
48dc4_hash: Callable[..., int] = DC4.__hash__ # OK
50v4: Hashable = DC4(0) # OK
53@dataclass(eq=True, unsafe_hash=True)
58dc5_hash: Callable[..., int] = DC5.__hash__ # OK
60v5: Hashable = DC5(0) # OK
67 def __hash__(self) -> int:
71dc6_hash: Callable[..., int] = DC6.__hash__ # OK
73v6: Hashable = DC6(0) # OK
76@dataclass(frozen=True)
80 def __eq__(self, other) -> bool:
81 return self.a == other.a
84dc7_hash: Callable[..., int] = DC7.__hash__ # OK
86v7: Hashable = DC7(0) # OK