
Eric S. Raymond wrote:
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.
Guido van Rossum wrote:
Yes, this is a good thing. Easy to do on lists and dicts. Questions:
- How to spell it? x.freeze()? x.readonly()?
I'm not so sure. There seem to be many issues here. More questions: What's the difference between a frozen list and a tuple? Is a frozen list hashable?
- Should this reversible? I.e. should there be an x.unfreeze()?
What if two threads lock and then unlock the same structure?
- Should we support something like this for instances too? Sometimes it might be cool to be able to freeze changing attribute values...
If you do this, i bet people will immediately want to freeze individual attributes. Some might be confused by a.x = [1, 2, 3] lock(a.x) # intend to lock the attribute, not the list a.x = 3 # hey, why is this allowed? What does locking an extension object do? What happens when you lock an object that implements list or dict semantics? Do we care that locking a UserList accomplishes nothing? Should unfreeze/unlock() be disallowed in restricted mode? -- ?!ng No software is totally secure, but using [Microsoft] Outlook is like hanging a sign on your back that reads "PLEASE MESS WITH MY COMPUTER." -- Scott Rosenberg, Salon Magazine