[Python-Dev] Declaring setters with getters (original) (raw)
Guido van Rossum guido at python.org
Sat Nov 10 22:17:39 CET 2007
- Previous message: [Python-Dev] Declaring setters with getters
- Next message: [Python-Dev] Declaring setters with getters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Nov 10, 2007 11:09 AM, Steven Bethard <steven.bethard at gmail.com> wrote:
On Nov 10, 2007 11:31 AM, Guido van Rossum <guido at python.org> wrote: > Unless I get negative feedback really soon I plan to submit this later > today. I've tweaked the patch slightly to be smarter about replacing > the setter and the deleter together if they are the same object.
Definitely +1 on the basic patch. Could you explain briefly the advantage of the "hack" that merges the set and del methods? Looking at the patch, I get a little nervous about this:: @foo.setter def foo(self, value=None): if value is None: del self.foo else: self.foo = abs(value) That means that
c.foo = None
is equivalent todel c.foo
right?
Which is sometimes convenient. But thinking about this some more I think that if I wanted to use the same method as setter and deleter, I could just write
@foo.setter @foo.deleter def foo(self, value=None): ...
So I'm withdrawing the hacks, making the code and semantics much simpler.
See propset3.diff in http://bugs.python.org/issue1416 .
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Declaring setters with getters
- Next message: [Python-Dev] Declaring setters with getters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]