`attrs` vs `dataclasses` ? I think they’re similar...
# general
c
attrs
vs
dataclasses
? I think they’re similar, but haven’t used
attrs
. Am curious about if there’s any major pros/cons between them?
m
There is a discussion on dataclass's github: https://github.com/ericvsmith/dataclasses/issues/60, as well es a short section on the pep: https://www.python.org/dev/peps/pep-0557/#why-not-just-use-attrs
👍 1
I personally use dataclasses a lot, and make do for the missing features in
__post_init__
, so I guess I'm in a similar boat as you.
p
I haven’t used attrs. I prefer using stdlib features unless there’s another lib provides a much better UX (err DX? Developer Experience?) hopefully without a significant performance penalty. So,
dataclasses
is my go to.
c
Thanks, those were enlightening reads, as well as https://github.com/ericvsmith/dataclasses/issues/19
e
I'm forced to use attrs in Pex since Pex supports Python 2.7. From an ergonomics perspective its stricly superior with special handling for _private, converters, defaulters and validators.
👍 1
In every other aspect its equivalent to dataclasses (except for its slots handling, which I haven't tried / perfed-out).