[Python-Dev] Making mutable objects readonly
M.-A. Lemburg
mal@lemburg.com
Wed, 31 Jan 2001 13:01:24 +0100
Guido van Rossum wrote:
>
> [ESR]
> > 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()?
How about .lock() and .unlock() ?
> - Should this reversible? I.e. should there be an x.unfreeze()?
Yes. These low-level locks could be used in thread programming
since the above calls are C level functions and thus thread safe
w/r to the global interpreter lock.
> - Should we support something like this for instances too? Sometimes
> it might be cool to be able to freeze changing attribute values...
Sure :)
Eric, could you write a PEP for this ?
--
Marc-Andre Lemburg
______________________________________________________________________
Company: http://www.egenix.com/
Consulting: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/