TL;DR
If you’re using Python 3.7+, dataclasses will save you a bunch of time, make your code cleaner, and maybe even make your code more...
For further actions, you may consider blocking this person and/or reporting abuse
How is it different from the attrs package? Other than it’s being builtin?
Really nothing other than the fact that it's built in. I've never really used attrs, does it have any features that dataclasses are missing? Or, put another way, is there any reason to use attrs now that the builtin dataclasses are available?
I honestly don’t know, i never used either.
Also, it’s not a problem if they are the same… it’s always delightful seeing a community effort included in the standard library. The same happened to
unittest
andmock
(now available asunittest.mock
).See also the attrs library, which predates @dataclass and works on more versions of Python.
This is the same as case classes in Scala or data classes in Kotlin. They reduce boilerplate code and provide some nice features for comparing or serialising objects.
Great post, cant wait to experiment with these!
Cool! reminds me of the data transfer objects in java that's abound in JEE frameworks
This is coming a little late, but I imagine these would be useful if the class definition is opaque or not readily available.
Why should you use @dataclass??? Because of Strawberry!!!!!!!!!!!!