← 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
"""
2
Tests
the
synthesis
of
the
__hash__
method
in
a
dataclass
.
3
"""
4
5
from
dataclasses
import
dataclass
6
from
typing
import
Hashable
7
8
9
@dataclass
10
class
DC1
:
11
a
:
int
12
13
14
# This should generate an error because DC1 isn't hashable.
15
v1
:
Hashable
=
DC1
(
0
)
# E
Expected a ty diagnostic for this line
16
17
18
@dataclass
(
eq
=
True
,
frozen
=
True
)
19
class
DC2
:
20
a
:
int
21
22
23
v2
:
Hashable
=
DC2
(
0
)
24
25
26
@dataclass
(
eq
=
True
)
27
class
DC3
:
28
a
:
int
29
30
31
# This should generate an error because DC3 isn't hashable.
32
v3
:
Hashable
=
DC3
(
0
)
# E
Expected a ty diagnostic for this line
33
34
35
@dataclass
(
frozen
=
True
)
36
class
DC4
:
37
a
:
int
38
39
40
v4
:
Hashable
=
DC4
(
0
)
41
42
43
@dataclass
(
eq
=
True
,
unsafe_hash
=
True
)
44
class
DC5
:
45
a
:
int
46
47
48
v5
:
Hashable
=
DC5
(
0
)
49
50
51
@dataclass
(
eq
=
True
)
52
class
DC6
:
53
a
:
int
54
55
def
__hash__
(
self
)
->
int
:
56
return
0
57
58
59
v6
:
Hashable
=
DC6
(
0
)
60
61
62
@dataclass
(
frozen
=
True
)
63
class
DC7
:
64
a
:
int
65
66
def
__eq__
(
self
,
other
)
->
bool
:
67
return
self
.
a
==
other
.
a
68
69
70
v7
:
Hashable
=
DC7
(
0
)