Hi,
I would like to correct some attrs misconceptions. :)
- Custom
__init__: you can always pass @attrs(init=False) and no __init__ is generated so that doesn’t seem like a fair criticism (basically: you have to pass an argument :))?
- Subclassing:
attrs has wonderful support for sub-classing; it just works a bit differently. From the examples page:
>>> @attr.s
... class A(object):
... a = attr.ib()
... def get_a(self):
... return self.a
>>> @attr.s
... class B(object):
... b = attr.ib()
>>> @attr.s
... class C(B, A):
... c = attr.ib()
>>> i = C(1, 2, 3)
>>> i
C(a=1, b=2, c=3)
>>> i == C(1, 2, 3)
True
>>> i.get_a()
1
In other words: if you’re composing attrs classes, everything works out of the box as you’d wish to. If you’re mixing in 3rd party classes it’s more complicated and you’ll have to write your own __init__.
Cheers,
—h
Hi,
I would like to correct some attrs misconceptions. :)
__init__: you can always pass@attrs(init=False)and no__init__is generated so that doesn’t seem like a fair criticism (basically: you have to pass an argument :))?attrshas wonderful support for sub-classing; it just works a bit differently. From the examples page:In other words: if you’re composing attrs classes, everything works out of the box as you’d wish to. If you’re mixing in 3rd party classes it’s more complicated and you’ll have to write your own
__init__.Cheers,
—h