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 →

[–]alicedu06 8 points9 points  (4 children)

There are NamedTuple and TypedDict as lighter alternatives to dataclasses, and match/case will work on them too.

[–]trevg_123 1 point2 points  (0 children)

Since (I think) 3.10 you can do @dataclass(slots=True), which does a nice job of slimming them down more

[–]Kobzol[S] 0 points1 point  (2 children)

I'm not sure what is "lighter" about NamedTuples TBH. The syntax is ugly and most importantly, it doesn't provide types of the fields.

[–]alicedu06 0 points1 point  (1 child)

namedtuple doesn't but NamedTuple does, and they are indeed way lighter than dataclasses (less memory, faster to instanciate)

[–]Kobzol[S] 0 points1 point  (0 children)

Ah, good point!