← 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"""
2Tests the synthesized comparison methods for dataclasses.
3"""
4
5from dataclasses import dataclass
6
7@dataclass(order=True)
8class DC1:
9 a: str
10 b: int
13@dataclass(order=True)
14class DC2:
15 a: str
16 b: int
19dc1_1 = DC1("", 0)
20dc1_2 = DC1("", 0)
22if dc1_1 < dc1_2:
23 pass
25if dc1_1 <= dc1_2:
26 pass
28if dc1_1 > dc1_2:
29 pass
31if dc1_1 >= dc1_2:
32 pass
34if dc1_1 == dc1_2:
35 pass
37if dc1_1 != dc1_2:
38 pass
40if dc1_1 == None:
41 pass
43if dc1_1 != None:
44 pass
46dc2_1 = DC2("hi", 2)
48# This should generate an error because the types are
49# incompatible.
50if dc1_1 < dc2_1: # E:
[unsupported-operator] Operator `<` is not supported between objects of type `DC1` and `DC2`
51 pass
53if dc1_1 != dc2_1:
54 pass