On 10/31/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > As long as we're all tossing out ideas here, my 2ยข. I vastly prefer > this: > > On 02:43 am, [EMAIL PROTECTED] wrote: > >On 10/31/07, Fred Drake <[EMAIL PROTECTED]> wrote: > > >> @property.set > >> def attribute(self, value): > >> self._ignored = value > > to this: > > @property.set(attribute) > > def attribute(self, value): > > self._ignored = value > > since I don't see any additional expressive value in the latter, and it > provides an opportunity to make a mistake.
I was expecting this would be brought up, but that just ain't gonna happen. If you don't repeat the name, the decorator has to root around in the surrounding scope, which is fraught with peril. Solutions based on sys._getframe() have been around for years (e.g. several the Cookbook recipes) and if I had approved of that technique I would have adopted one long ago. However I don't approve of it. It has always been and will always continue to be my position that these are semantically unkosher, because it means that you can't wrap them in convenience functions or invoke them in different contexts, and that means that the semantics are hard to explain. If you really want another argument, repeating the property name actually does have an additional use case: you can have a read-only property with a corresponding read-write property whose name differs. E.g. class C(object): @property def encoding(self): return ... @propset(encoding) def encoding_rw(self, value): ... c = C() c.encoding = "ascii" # Fails c.encoding_rw = "ascii" # Works I've seen people do this in the filesystem: a read-only version that may be cached or replicated, and a separate writable version. Reading the writable version works too, of course. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com