I wanted to make a similar feature to ECMAScript 5 "frozen" object where you can't change anything on it.
Did this:
class Fixed(object):
frzn = 'I AM AWESOME'
def holdset(_,val):
_.frzn = _.frzn
print "frozen is frozen not setting to ", val
frozen = property(fset=holdset)
@classmethod
def __setattr__(self, name, val):
if name=="frozen":
print "You can't unfreeze the frozen"
else:
self.name = val
dd = Fixed()
dd.frozen = 12312312
dd.frozen = 'AA'
Fixed.frozen = {}
print dd.frozen
print Fixed.frozen
Which gives
You can't unfreeze the frozen
You can't unfreeze the frozen
{}
{}
The first two assignments fail, when they reference the attribute as an instance member. The third assignment succeeds, when the attribute is referenced as a class member.
I don't understand why.
How can I make
Fixed.frozen = {}
Fail in the same way the other assignments did? And why doesn't it?