Making immutable instances
Giovanni Bajo
noway at sorry.com
Thu Nov 24 02:52:10 EST 2005
Mike Meyer wrote:
> Note that this property of __slots__ is an implementation detail. You
> can't rely on it working in the future.
I don't "rely" on it. I just want to catch bugs in my code.
> I'm curious as to why you care if people add attributes to your
> "immutable" class. Personally, I consider that instances of types
> don't let me add attributes to be a wart.
To catch stupid bugs, typos and whatnot. If an instance is immutable, you can't
modify it, period. If you do it, it's a bug. So why not have the bug raises an
exception, rather than go unnoticed?
I don't see your point, either. Why would you want to add attributes to an
object documented to be immutable?
--
Giovanni Bajo
More information about the Python-list
mailing list