11-- Test cases for dataclasses based on the attrs library, where auto_attribs=True
22
33[case testRunAttrsclass]
4- import attrs
4+ import attr
55from typing import Set, List, Callable, Any
66
7- @attrs.define
7+ @attr.s(auto_attribs=True)
88class Person1:
99 age : int
1010 name : str
@@ -18,19 +18,19 @@ def testBool(p: Person1) -> bool:
1818 else:
1919 return False
2020
21- @attrs.define
21+ @attr.s(auto_attribs=True)
2222class Person1b(Person1):
2323 id: str = '000'
2424
25- @attrs.define
25+ @attr.s(auto_attribs=True)
2626class Person2:
2727 age : int
28- name : str = 'robot'
28+ name : str = attr.ib(default= 'robot')
2929
30- @attrs.define( order=True)
30+ @attr.s(auto_attribs=True, order=True)
3131class 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)
3434
3535 def get_age(self) -> int:
3636 return (self.age)
@@ -49,7 +49,7 @@ def get_next_age(g: Callable[[Any], int]) -> Callable[[Any], int]:
4949 return g(a) + 1
5050 return f
5151
52- @attrs.define
52+ @attr.s(auto_attribs=True)
5353class Person4:
5454 age : int
5555 _name : str = 'Bot'
@@ -62,10 +62,10 @@ class Person4:
6262 def name(self) -> str:
6363 return self._name
6464
65- @attrs.define
65+ @attr.s(auto_attribs=True)
6666class 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)
6969
7070 def __attrs_post_init__(self):
7171 self.y = self.x + 1
@@ -165,10 +165,10 @@ assert isinstance(Person3().get_age, BuiltinMethodType)
165165
166166
167167[case testRunAttrsclassNonAuto]
168- import attrs
168+ import attr
169169from typing import Set, List, Callable, Any
170170
171- @attrs.define
171+ @attr.s
172172class Person1:
173173 age = attr.ib(type=int)
174174 name = attr.ib(type=str)
@@ -182,16 +182,16 @@ def testBool(p: Person1) -> bool:
182182 else:
183183 return False
184184
185- @attrs.define
185+ @attr.s
186186class Person1b(Person1):
187187 id = attr.ib(type=str, default='000')
188188
189- @attrs.define
189+ @attr.s
190190class Person2:
191191 age = attr.ib(type=int)
192192 name = attr.ib(type=str, default='robot')
193193
194- @attrs.define (order=True)
194+ @attr.s (order=True)
195195class Person3:
196196 age = attr.ib(type=int, default=6)
197197 friendIDs = attr.ib(factory=list, type=List[int])
@@ -213,7 +213,7 @@ def get_next_age(g: Callable[[Any], int]) -> Callable[[Any], int]:
213213 return g(a) + 1
214214 return f
215215
216- @attrs.define
216+ @attr.s
217217class Person4:
218218 age = attr.ib(type=int)
219219 _name = attr.ib(type=str, default='Bot')
@@ -226,7 +226,7 @@ class Person4:
226226 def name(self) -> str:
227227 return self._name
228228
229- @attrs.define
229+ @attr.s
230230class Point:
231231 x = attr.ib(type=int, converter=int)
232232 y = attr.ib(type=int, init=False)
0 commit comments