[Python-Dev] Extended Function syntax

"Martin v. Löwis" martin@v.loewis.de
Fri, 24 Jan 2003 12:52:32 +0100


Duncan Booth wrote:
> How about this:
> 
>     class A(object):
>  
>       def foo(self, foo) [property.set]:
>         "Setter for property 'foo'."
>         self.__foo = foo
> 
>       def foo(self) [property.get]:
>         "Getter for property 'foo'."
>         return self.__foo

This is beautiful, but it does not work: when defining the getter, you 
need both the old property, and the new function object. Looking at your 
code

    def set(fn):
        if isinstance(fn, property):
            return property(fn.fget, fn, fn.fdel, fn.__doc__)

you first assume fn is the property object, and then assume it is the 
setter function.

Of course, there is no reason why the namespace-under-construction 
couldn't be passed to the annotation, but that would be an extension to 
the protocol.

Martin