← Back to index

dataclasses_hash.py

True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 0
FP: 0
FN: 2
Optional: 0 / 0
1"""
2Tests the synthesis of the __hash__ method in a dataclass.
3"""
4
5from dataclasses import dataclass
6from typing import Hashable
7
8
9@dataclass
10class DC1:
11 a: int
14# This should generate an error because DC1 isn't hashable.
15v1: Hashable = DC1(0) # E
Expected a ty diagnostic for this line
18@dataclass(eq=True, frozen=True)
19class DC2:
20 a: int
23v2: Hashable = DC2(0)
26@dataclass(eq=True)
27class DC3:
28 a: int
31# This should generate an error because DC3 isn't hashable.
32v3: Hashable = DC3(0) # E
Expected a ty diagnostic for this line
35@dataclass(frozen=True)
36class DC4:
37 a: int
40v4: Hashable = DC4(0)
43@dataclass(eq=True, unsafe_hash=True)
44class DC5:
45 a: int
48v5: Hashable = DC5(0)
51@dataclass(eq=True)
52class DC6:
53 a: int
55 def __hash__(self) -> int:
56 return 0
59v6: Hashable = DC6(0)
62@dataclass(frozen=True)
63class DC7:
64 a: int
66 def __eq__(self, other) -> bool:
67 return self.a == other.a
70v7: Hashable = DC7(0)