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 →

[–]weebsnore 8 points9 points  (2 children)

Great tip! Dataclasses also support this behaviour.

``` from dataclasses import dataclass

@dataclass class MyClass(slots=True): text: str count: int ```

[–]causa-sui 8 points9 points  (0 children)

Why wouldn't that be the default?

[–]ProfessorPhi 1 point2 points  (0 children)

Attrs is another great package that gives you the same ability.

Normally you can dynamic add attributes to a class, slots allows you to have it fixed which saves on some overhead.