https://pantsbuild.org/ logo
c

curved-television-6568

10/22/2021, 5:40 AM
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

millions-kilobyte-51167

10/22/2021, 6:22 AM
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

proud-dentist-22844

10/22/2021, 6:33 AM
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

curved-television-6568

10/22/2021, 6:51 AM
Thanks, those were enlightening reads, as well as https://github.com/ericvsmith/dataclasses/issues/19
e

enough-analyst-54434

10/22/2021, 1:53 PM
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).
3 Views