[Python-Dev] properties and block statement

Antoine Pitrou solipsis at pitrou.net
Tue Oct 18 19:17:14 CEST 2005


>     What would this mythical block statement look like that would make
> properties easier to write than the above late-binding or the subclass
> Property recipe?

I suppose something like:

class C(object):
    x = prop:
        """ Yay for property x! """
        def __get__(self):
            return self._x
        def __set__(self, value):
            self._x = x

and then:

def prop(@block):
    return property(
        fget=block.get("__get__"),
        fset=block.get("__set__"),
        fdel=block.get("__delete__"),
        doc=block.get("__doc__", ""),
    )

(where "@bargs" would be the syntax to refer to block args as a dict,
the same way "**kargs" already exist)





More information about the Python-Dev mailing list