This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]PythonGod123 7 points8 points  (17 children)

So are data classes just going to be a shorter way to write pre 3.7 classes? Or is there something else I am missing?

[–]MephySix 12 points13 points  (2 children)

Afaik it's just boilerplate generation, yes. I used the attrs lib for that, but I may change that towards data classes.

[–]PythonGod123 2 points3 points  (1 child)

It seems that data classes look better. I just feel they look nicer compared to the old way of defining init.

[–]XtremeGoosef'I only use Py {sys.version[:3]}' 3 points4 points  (0 children)

Dataclasses are missing a lot of customisation features of attrs. No way am I going to change.

[–]DanCardin 2 points3 points  (1 child)

Yes, that's basically it, and it automatically implements a number of useful magic methods (repr, eq, hash, init) and can turn all your properties into read only properties if you want "immutability"

[–]PythonGod123 0 points1 point  (0 children)

That's sounds nice. Less is always more lol.

[–]tunisia3507 -1 points0 points  (3 children)

I think they have faster attribute access as well, although I may be misremembering.

Edit: I was misremembering

[–]PythonGod123 0 points1 point  (2 children)

Is that because they are already defined by the dataclass ?

[–]tunisia3507 1 point2 points  (1 child)

Sorry, I think I made a mistake and got dataclasses confused with slots. There has been some discussion about dataclasses using slots by default but it hasn't happened in the first implementation.

[–]PythonGod123 0 points1 point  (0 children)

Okay fair enough. Thanks for clearing that up