On Wed, May 15, 2013 at 12:15 PM, dieter <die...@handshake.de> wrote: > > If Python would automatically redecorate overridden methods in a derived > class, I would have no control over the process. What if I need > the undecorated method or a differently decorated method (an > uncached or differently cached method, in my case)? >
On a second thought, I am convinced by your argument. > Your getter/setter use case can quite easily be solved > with a class "DelayedMethodAccessor": > > class DelayedMethodAccess(object): > """ > def __init__(self, name): self.__name = name > def __call__(self, inst, *args, **kw): > return getattr(inst, self.__name)(*args, **kw) > > You can then use: > > prop = property(DelayedMethodAccess("<getter_name>"), ...) > > Or define a new decorator "property_by_name" and then > use > > prop = property_by_name("<getter_name>", ...) > > Of course, this requires that the property name and the getter/setter names > differ, but this should be naturally enough. > > > Python's current behavior is very natural once you know that > decorators are just syntactic sugar and > > @<decorator_expression> > def <f>... > > simply means: > > def <f>... > f = <decorator_expressen>(f) > > True, this is no perfect fit for all use cases - but > such a fit (if it existed at all) would have to be so complex > that only experts could understand it. Thanks for these really nice patterns. They fits my problem very well.
-- http://mail.python.org/mailman/listinfo/python-list