As long as we're all tossing out ideas here, my 2ยข. I vastly prefer this: On 02:43 am, steven.bethard at gmail.com wrote: >On 10/31/07, Fred Drake <fdrake at acm.org> wrote: >> @property.set >> def attribute(self, value): >> self._ignored = value to this: > @property.set(attribute) > def attribute(self, value): > self._ignored = value since I don't see any additional expressive value in the latter, and it provides an opportunity to make a mistake. The decorator syntax's main value, to me, is eliminating the redundancy in: def foo(): ... foo = bar(foo) eliminating the possibility of misspelling "foo" one of those three times. and removing a lot of finger typing. The original proposal here re-introduces half of this redundancy. I think I can see why Guido did it that way - it makes the implementation a bit more obvious - but decorators are already sufficiently "magic" that I wouldn't mind a bit more to provide more convenience, in what is apparently just a convenience mechanism. And, since everyone else is sharing their personal current way of idiomatically declaring dynamic properties, here's mine; abusing the "class" statement instead of decorators: from epsilon.descriptor import attribute class Stuff(object): class foo(attribute): "you can put a docstring in the obvious place" def set(self, value): print 'set foo!' self._foo = value + 4 def get(self): return self._foo + 3 s = Stuff() s.foo = 0 print 's.foo:', s.foo I'd be glad of a standard, accepted way to do this though, since it's really just a spelling issue and it would be nice to reduce the learning curve between all the different libraries which define dynamic attributes.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4