Total Complexity | 3 |
Total Lines | 118 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import typing |
||
2 | |||
3 | from structured_data import adt |
||
4 | |||
5 | |||
6 | @adt.adt(repr=False, eq=False, order=False) |
||
7 | class AllFalse: |
||
8 | |||
9 | Left: adt.Ctor[int] |
||
10 | Right: adt.Ctor[str] |
||
11 | |||
12 | repr = False |
||
13 | eq = False |
||
14 | order = False |
||
15 | |||
16 | |||
17 | @adt.adt(repr=False, eq=True, order=False) |
||
18 | class EqOnly: |
||
19 | |||
20 | Left: adt.Ctor[int] |
||
21 | Right: adt.Ctor[str] |
||
22 | |||
23 | repr = False |
||
24 | eq = True |
||
25 | order = False |
||
26 | |||
27 | |||
28 | @adt.adt(repr=False, eq=True, order=True) |
||
29 | class MinimalOrder: |
||
30 | |||
31 | Left: adt.Ctor[int] |
||
32 | Right: adt.Ctor[str] |
||
33 | |||
34 | repr = False |
||
35 | eq = True |
||
36 | order = True |
||
37 | |||
38 | |||
39 | @adt.adt(repr=True, eq=False, order=False) |
||
40 | class ReprOnly: |
||
41 | |||
42 | Left: adt.Ctor[int] |
||
43 | Right: adt.Ctor[str] |
||
44 | |||
45 | repr = True |
||
46 | eq = False |
||
47 | order = False |
||
48 | |||
49 | |||
50 | @adt.adt(repr=True, eq=True, order=False) |
||
51 | class ReprAndEq: |
||
52 | |||
53 | Left: adt.Ctor[int] |
||
54 | Right: adt.Ctor[str] |
||
55 | |||
56 | repr = True |
||
57 | eq = True |
||
58 | order = False |
||
59 | |||
60 | |||
61 | @adt.adt(repr=True, eq=True, order=True) |
||
62 | class ReprAndOrder: |
||
63 | |||
64 | Left: adt.Ctor[int] |
||
65 | Right: adt.Ctor[str] |
||
66 | |||
67 | repr = True |
||
68 | eq = True |
||
69 | order = True |
||
70 | |||
71 | |||
72 | @adt.adt |
||
73 | class CustomEq: |
||
74 | |||
75 | Left: adt.Ctor[int] |
||
76 | Right: adt.Ctor[str] |
||
77 | |||
78 | def __eq__(self, other): |
||
79 | return self is other |
||
80 | |||
81 | |||
82 | @adt.adt |
||
83 | class CustomInitSubclass: |
||
84 | |||
85 | Left: adt.Ctor[int] |
||
86 | Right: adt.Ctor[str] |
||
87 | |||
88 | subclasses: 'typing.List[typing.Type[CustomInitSubclass]]' = [] |
||
89 | dummy_variable: 'MyList[CustomInitSubclass]' |
||
90 | |||
91 | def __init_subclass__(cls, **kwargs): |
||
92 | cls.subclasses.append(cls) |
||
93 | return super().__init_subclass__(**kwargs) |
||
94 | |||
95 | |||
96 | MyList = typing.List |
||
97 | |||
98 | |||
99 | @adt.adt |
||
100 | class CustomNew: |
||
101 | |||
102 | Left: adt.Ctor[int] |
||
103 | Right: adt.Ctor[str] |
||
104 | |||
105 | instances: 'int' = 0 |
||
106 | |||
107 | def __new__(cls, args): |
||
108 | self = super().__new__(cls, args) |
||
109 | CUSTOM_NEW_INSTANCES.append(self) |
||
110 | CustomNew.instances += 1 |
||
111 | return self |
||
112 | |||
113 | |||
114 | CUSTOM_NEW_INSTANCES: typing.List[CustomNew] = [] |
||
115 | |||
116 | |||
117 | TEST_CLASSES = [AllFalse, EqOnly, MinimalOrder, ReprOnly, ReprAndEq, ReprAndOrder] |
||
118 |