[Python-Dev] Declaring setters with getters

Guido van Rossum guido at python.org
Thu Nov 1 20:17:22 CET 2007


-1. Looks like more magic, not less, to me.

On 11/1/07, Tony Lownds <tony at pagedna.com> wrote:
>
> On Nov 1, 2007, at 10:26 AM, glyph at divmod.com wrote:
> > This is a minor nit, as with all decorators that take an argument,
> > it seems like it sets up a hard-to-debug error condition if you were
> > to accidentally forget it:
> >
> >   @property
> >   def foo(): ...
> >   @property.set
> >   def foo(): ...
> >
> > would leave you with 'foo' pointing at something that wasn't a
> > descriptor at all.  Is there a way to make that more debuggable?
>
> How about this: give the property instance a method that changes a
> property from read-only to read-write.
> No parens, no frame magic. As a small bonus, the setter function would
> not have to be named the same as the
> property.
>
> class A(object):
>    @property
>    def foo(self):
>      return 1
>
>    @foo.setter
>    def set_foo(self, value):
>      print 'set:', value
>
> -Tony
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list