← Back to index
dataclasses_order.py
True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 1
FP: 0
FN: 0
Optional: 0 / 0
1
"""
2
Tests
the
synthesized
comparison
methods
for
dataclasses
.
3
"""
4
5
from
dataclasses
import
dataclass
6
7
@dataclass
(
order
=
True
)
8
class
DC1
:
9
a
:
str
10
b
:
int
11
12
13
@dataclass
(
order
=
True
)
14
class
DC2
:
15
a
:
str
16
b
:
int
17
18
19
dc1_1
=
DC1
(
""
,
0
)
20
dc1_2
=
DC1
(
""
,
0
)
21
22
if
dc1_1
<
dc1_2
:
23
pass
24
25
if
dc1_1
<=
dc1_2
:
26
pass
27
28
if
dc1_1
>
dc1_2
:
29
pass
30
31
if
dc1_1
>=
dc1_2
:
32
pass
33
34
if
dc1_1
==
dc1_2
:
35
pass
36
37
if
dc1_1
!=
dc1_2
:
38
pass
39
40
if
dc1_1
==
None
:
41
pass
42
43
if
dc1_1
!=
None
:
44
pass
45
46
dc2_1
=
DC2
(
"hi"
,
2
)
47
48
# This should generate an error because the types are
49
# incompatible.
50
if
dc1_1
<
dc2_1
:
# E:
[unsupported-operator] Operator `<` is not supported between objects of type `DC1` and `DC2`
51
pass
52
53
if
dc1_1
!=
dc2_1
:
54
pass