As long as we're all tossing out ideas here, my 2¢. I vastly prefer
this:
On 02:43 am, [EMAIL PROTECTED] wrote:
On 10/31/07, Fred Drake <[EMAIL PROTECTED]> 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.
_______________________________________________
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