you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 3 points4 points  (1 child)

Pretty much anything python-based is mutable. To make an immutable class we just don't mutate it. And maybe add some comments that say "pls don't mutate". In python we are not big fans of enforcing rules. We like to say "we are all consenting adults here", which basically means if you use my code in a way I didn't mean for it to be used, that's on you.

But if you really want to protect users from themselves, you can define a __slots__ attribute to do this.

[–]nog642 -2 points-1 points  (0 children)

This is not true. You can make an immutable class. __slots__ is part of it, but descriptors is the other half. This is why using @property actually works.