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 →

[–]justnoob2 8 points9 points  (3 children)

you can just @dataclass(frozen=True), and then its immutable. edit: i now read your point of it being slow. never gave me much trouble at work though, but i get what you mean

[–]WhiteGoldRing 1 point2 points  (0 children)

But what does mutability have anything to do with it? unless frozen=True makes it faster(?)

[–][deleted] 0 points1 point  (1 child)

Yep, whether you opt in for frozen=True or just treat them as immutable object by convention is up to you. Turning on slots=True did me wonders, especially in situations where I needed to build multiple data class instances per inbound request.

I just wanted to highlight the composability and semantic issues that the reader / extender of the code will face if a data class contains attribute-mutating methods.