You are probably right that it is simply an agreement to make these read-only attributes selected in order to make the all or nothing property. It looks like it will be a bit more โPythonicโ to allow them to be assigned after the fact, but cannot find the rationale in the Python 2.2 release notes (when the properties were introduced).
In Objects / descrobject.c, the attributes of a property element are defined as read-only:
static PyMemberDef property_members[] = { {"fget", T_OBJECT, offsetof(propertyobject, prop_get), READONLY}, {"fset", T_OBJECT, offsetof(propertyobject, prop_set), READONLY}, {"fdel", T_OBJECT, offsetof(propertyobject, prop_del), READONLY}, {"__doc__", T_OBJECT, offsetof(propertyobject, prop_doc), READONLY}, {0} };
Also: if you replace READONLY with 0 and compile, all it takes to assign fget, fset, .. :
class Test(object): def __init__(self): self.flag = True prop = property(lambda self: self.flag) obj = Test() print obj.prop Test.prop.fget = lambda self: not self.flag print obj.prop
Conclusion:
True False
source share