Re: [Python-Dev] Declaring setters with getters

I'd like to make this [propset] a standard built-in,
+1 -- I find this to be an attractive syntax
I'd also like to change property so that the doc string defaults to the doc string of the getter.
+1 -- This should also be done for classmethod, staticmethod, and anything else that wraps functions. Alternatively, the doc string could be made a little more informative: __doc__ = 'property of function %s: %s' % (f.__name__, f.__doc__) Raymond

On 10/31/07, Raymond Hettinger <python@rcn.com> wrote:
I'd like to make this [propset] a standard built-in,
+1 -- I find this to be an attractive syntax
I'd also like to change property so that the doc string defaults to the doc string of the getter.
+1 -- This should also be done for classmethod, staticmethod, and anything else that wraps functions.
With this level of support, it could be implemented by this afternoon! (and backported to 2.4 within a week. ;-)
Alternatively, the doc string could be made a little more informative:
__doc__ = 'property of function %s: %s' % (f.__name__, f.__doc__)
Hm, not clear that helps. It's not a property of the function. We should just teach users to write docstrings that read well for this use case. -- --Guido van Rossum (home page: http://www.python.org/~guido/)

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 31, 2007, at 2:14 PM, Guido van Rossum wrote:
On 10/31/07, Raymond Hettinger <python@rcn.com> wrote:
I'd like to make this [propset] a standard built-in,
+1 -- I find this to be an attractive syntax
I'd also like to change property so that the doc string defaults to the doc string of the getter.
+1 -- This should also be done for classmethod, staticmethod, and anything else that wraps functions.
With this level of support, it could be implemented by this afternoon! (and backported to 2.4 within a week. ;-)
I know you're joking about the backporting. Neal, no sneaking this into 2.5.2 now! :) BTW, +1 on this. I like Fred's suggestion of property.set(). - -Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iQCVAwUBRyk4kHEjvBPtnXfVAQJ5SQP/Z4uofrSz0L5hgHvaC5MmGlFqxO2O/i8q pZUurzbcRENCXhKSat5+qymyfOWyeO9rCgUbHq81af5tyUIDt9uo+6JxtBwVniEN Fcc3qMmjNhBi9if1Rn1S8jTG0AC3KEHuL4qZmghAY7Lz4/8jOjtQmAWubJ+LmQlE hxN+sdYqkm8= =gA2F -----END PGP SIGNATURE-----

On Oct 31, 2007, at 10:23 PM, Barry Warsaw wrote:
BTW, +1 on this. I like Fred's suggestion of property.set().
Thanks! Of all the proposals that have been presented, I still like that the best. Guido's use case of wanting to give the r/w property a different name than the r/o property is a good one, though I've not run across it myself. I'd be satisfied with passing in the origin property, though I'd want to be able to do that for the get method as well as the set and delete methods. That would better support being able to extend a property in a derived class. For example: class Base(object): @property def attribute(self): return 42 class Derived(Base): @property.get(Base.__dict__["attribute"]) def attribute(self): self.do_something() return super(Derived, self).attribute What I don't like is the difficulty of getting the raw descriptor from the base class. It would be good to be able to say: class Derived(Base): @property.get(Base.attribute) def attribute(self): self.do_something() return super(Derived, self).attribute I doubt that's all that hard to achieve, at least for a known property type. To support descriptors of completely different types, the syntax from the first example may be required unless some other crutch is added. -Fred -- Fred Drake <fdrake at acm.org>

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>
participants (4)
-
Barry Warsaw
-
Fred Drake
-
Guido van Rossum
-
Raymond Hettinger