[Python-Dev] Making mutable objects readonly
Guido van Rossum
Mon, 29 Jan 2001 21:17:27 -0500
> For different reasons, I'd like to be able to set a constant flag on a
> object instance. Simple semantics: if you try to assign to a
> member or method, it throws an exception.
> Application? I have a large Python program that goes to a lot of effort
> to build elaborate context structures in core. It would be nice to know
> they can't be even inadvertently trashed without throwing an exception I
> can watch for.
Yes, this is a good thing. Easy to do on lists and dicts. Questions:
- How to spell it? x.freeze()? x.readonly()?
- Should this reversible? I.e. should there be an x.unfreeze()?
- Should we support something like this for instances too? Sometimes
it might be cool to be able to freeze changing attribute values...
--Guido van Rossum (home page: http://www.python.org/~guido/)