[Python-Dev] Re: new syntax for wrapping (PEP 318) (original) (raw)

Alan Green alan.green at cardboard.nu
Fri Feb 27 16:00:35 EST 2004


Phillip J. Eby <pje telecommunity.com> writes: > At 11:25 AM 2/27/04 +0000, Alan Green wrote: > >It would be really spiffy if the decorator were able to run the decorated > >function and then have access to the function's locals dictionary. It would > >then be possible to define a property like so: > > > >class Foo(object): > > def bar(self) [property]: > > """ bar property docstring """ > > def get(self): > _> return self.bar > > def set(self, bar): > _> self.bar = bar >> -1. There were better alternatives proposed in the previous discussion on > PEP 218 and properties, like: >> def bar(self) [propertyget]: > # ... >> def bar(self,value) [propertyset]: > # ... >> def bar(self) [propertydel]: > # ... defs-inside-defs is a bit wierd, but has some advantages over individual methods: * Tells the reader that the get/set/del belong together * Gives a name to the property once, rather than one name three times * Makes a sensible place for the property's docstring Perhaps it might make more sense as:
class Foo(object): def [property] bar: def get(self): ...etc... In which case, it truly is getting beyond the scope of PEP318.

Alan



More information about the Python-Dev mailing list