> > I'm still torn whether to promote defining properties this way: > > > > [propget] > > def x(self): > > "Doc string for x" > > return self.__x > > > > [propset] > > def x(self, newx): > > self.__x = newx > > > > [propdel] > > def x(self): > > del self.__x > > > > but if people like this (whatever the decorator syntax :) we might as > > well make this the recommended way to define properties. > > Does that actually work? I.e. is there an implementation of propget, > propset, propdel so that this code introduces a property x? Yes, but it involves sys._getframe(). > My understanding is that above syntax would be short for> [propget] > def x(self): > "Doc string for x" > return self.__x > x = propget(x) > > def x(self, newx): > self.__x = newx > x = propset(x) > > def x(self): > del self.__x > x = propdel(x) > > Later assignments to x would override earlier ones, so that only > the propdel survives. No, the semantics of decorators are that the function name isn't actually assigned to for the first time until all decorators have been called. So the previous binding of that name is available to devious decorators like these. (This wasn't my idea -- someone else proposed it here first. :) --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4