1
1
-- Test cases for dataclasses based on the attrs library, where auto_attribs=True
2
2
3
3
[case testRunAttrsclass]
4
- import attrs
4
+ import attr
5
5
from typing import Set, List, Callable, Any
6
6
7
- @attrs.define
7
+ @attr.s(auto_attribs=True)
8
8
class Person1:
9
9
age : int
10
10
name : str
@@ -18,19 +18,19 @@ def testBool(p: Person1) -> bool:
18
18
else:
19
19
return False
20
20
21
- @attrs.define
21
+ @attr.s(auto_attribs=True)
22
22
class Person1b(Person1):
23
23
id: str = '000'
24
24
25
- @attrs.define
25
+ @attr.s(auto_attribs=True)
26
26
class Person2:
27
27
age : int
28
- name : str = 'robot'
28
+ name : str = attr.ib(default= 'robot')
29
29
30
- @attrs.define( order=True)
30
+ @attr.s(auto_attribs=True, order=True)
31
31
class Person3:
32
- age : int = attrs.field (default= 6)
33
- friendIDs : List[int] = attrs.field (factory= list)
32
+ age : int = attr.ib (default = 6)
33
+ friendIDs : List[int] = attr.ib (factory = list)
34
34
35
35
def get_age(self) -> int:
36
36
return (self.age)
@@ -49,7 +49,7 @@ def get_next_age(g: Callable[[Any], int]) -> Callable[[Any], int]:
49
49
return g(a) + 1
50
50
return f
51
51
52
- @attrs.define
52
+ @attr.s(auto_attribs=True)
53
53
class Person4:
54
54
age : int
55
55
_name : str = 'Bot'
@@ -62,10 +62,10 @@ class Person4:
62
62
def name(self) -> str:
63
63
return self._name
64
64
65
- @attrs.define
65
+ @attr.s(auto_attribs=True)
66
66
class Point:
67
- x : int = attrs.field (converter=int)
68
- y : int = attrs.field (init=False)
67
+ x : int = attr.ib (converter=int)
68
+ y : int = attr.ib (init=False)
69
69
70
70
def __attrs_post_init__(self):
71
71
self.y = self.x + 1
@@ -165,10 +165,10 @@ assert isinstance(Person3().get_age, BuiltinMethodType)
165
165
166
166
167
167
[case testRunAttrsclassNonAuto]
168
- import attrs
168
+ import attr
169
169
from typing import Set, List, Callable, Any
170
170
171
- @attrs.define
171
+ @attr.s
172
172
class Person1:
173
173
age = attr.ib(type=int)
174
174
name = attr.ib(type=str)
@@ -182,16 +182,16 @@ def testBool(p: Person1) -> bool:
182
182
else:
183
183
return False
184
184
185
- @attrs.define
185
+ @attr.s
186
186
class Person1b(Person1):
187
187
id = attr.ib(type=str, default='000')
188
188
189
- @attrs.define
189
+ @attr.s
190
190
class Person2:
191
191
age = attr.ib(type=int)
192
192
name = attr.ib(type=str, default='robot')
193
193
194
- @attrs.define (order=True)
194
+ @attr.s (order=True)
195
195
class Person3:
196
196
age = attr.ib(type=int, default=6)
197
197
friendIDs = attr.ib(factory=list, type=List[int])
@@ -213,7 +213,7 @@ def get_next_age(g: Callable[[Any], int]) -> Callable[[Any], int]:
213
213
return g(a) + 1
214
214
return f
215
215
216
- @attrs.define
216
+ @attr.s
217
217
class Person4:
218
218
age = attr.ib(type=int)
219
219
_name = attr.ib(type=str, default='Bot')
@@ -226,7 +226,7 @@ class Person4:
226
226
def name(self) -> str:
227
227
return self._name
228
228
229
- @attrs.define
229
+ @attr.s
230
230
class Point:
231
231
x = attr.ib(type=int, converter=int)
232
232
y = attr.ib(type=int, init=False)
0 commit comments