On Nov 1, 2007, at 9:18 PM, Fred Drake wrote:
Thanks! Of all the proposals that have been presented, I still like that the best.
I've attached a quick hack of an implementation, just to play with it and see how it feels. Here's an example use:
from property import property class Base(object): @property def attribute(self): print("Base.attribute (getter)") return 42 @property.get(attribute) def rwattribute(self): print("Base.rwattribute (getter)") return self.attribute * 2 @property.set(rwattribute) def rwattribute(self, value): print("Base.rwattribute (setter)") self.saved = value class Derived(Base): @property.get(Base.attribute) def roattribute(self): print("Derived.roattribute (getter)") return self.attribute / 2 -Fred -- Fred Drake <fdrake at acm.org>
import __builtin__ class property(__builtin__.property): __slots__ = () @classmethod def get(cls, base): return PropertyCombiner(cls, base).get @classmethod def set(cls, base): return PropertyCombiner(cls, base).set @classmethod def delete(cls, base): return PropertyCombiner(cls, base).delete class PropertyCombiner(object): __slots__ = "cls", "base" def __init__(self, cls, base): assert isinstance(base, __builtin__.property) assert issubclass(cls, property) self.cls = cls self.base = base def get(self, fget): return self.cls(fget, self.base.fset, self.base.fdel) def set(self, fset): return self.cls(self.base.fget, fset, self.base.fdel) def delete(self, fdel): return self.cls(self.base.fget, self.base.fset, fdel)
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com