On Dec 9, 2007 5:11 AM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Dec 9, 12:15 am, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > > Richard Jones a écrit : > > > > > > > > > Bruno Desthuilliers wrote: > > > > >>class A(object): > > >> @apply > > >> def a(): > > >> def fget(self): > > >> return self._a > > >> def fset(self, val): > > >> self._a = val > > >> return property(**locals()) > > >> def __init__(self): > > >> self.a = "foo" > > > > > That property setup seems overly complicated. As far as I can see, it only > > > avoids defining the setter in the class namespace, > > > > Yes. That's mosly the point. > > > > > yet is more complicated > > > and obfuscated to boot ;) > > > > Well, that's your POV, so what can I say ? It's indeed a bit hackish, > > and requires a couple minutes of attention the first time you see it. > > And you just have to learn it once !-) > > Perhaps 'return property(fget, fset)' would be easier to make sense of > than **locals() > > > Now I'd certainly prefer something like: > > > > class A(object): > > @propget > > def a(self): > > return self._a > > @propset > > def a(self, val): > > self._a = val > > > > But until there's something similar *builtin*, I'll stick to the @apply > > trick. > > At first sight, I like the look of this. Obviously I can't provide a > builtin implementation, but there's an easy way to achieve this. It > uses sys._getframe but there is no need to fiddle with metaclasses: >
Something very like this will be in 3k, and I believe is also being backported to 2.6. See python-dev archives for more. -- http://mail.python.org/mailman/listinfo/python-list