add default read-only setter to AliasProperty

This commit is contained in:
Ryan Pessa 2013-08-23 14:50:30 -05:00
parent 7a3b287f7b
commit 93a01604b6
1 changed files with 5 additions and 2 deletions

View File

@ -1219,16 +1219,19 @@ cdef class AliasProperty(Property):
self.use_cache = 0
self.bind_objects = list()
def __init__(self, getter, setter, rebind=False, **kwargs):
def __init__(self, getter, setter=None, rebind=False, **kwargs):
Property.__init__(self, None, **kwargs)
self.getter = getter
self.setter = setter
self.setter = setter or self.__read_only
self.rebind = rebind
v = kwargs.get('bind')
self.bind_objects = list(v) if v is not None else []
if kwargs.get('cache'):
self.use_cache = 1
def __read_only(self, _obj, _value):
raise AttributeError('property is read-only')
cdef init_storage(self, EventDispatcher obj, PropertyStorage storage):
Property.init_storage(self, obj, storage)
storage.getter = self.getter