You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@berrytj Yeah, I still think about it. I just don't want to make obvious mistake: to write decorator which will require special decorators order in each case. Which means that I want @composable decorator to be composable itself.
(Stating the obvious for a moment.) composable must return a class for operator overrides to work. So any decorator that returns only functions will fail if called after composable, e.g.:
I can only think of two ways around this, neither ideal. The first is to modify your decorators inline:
def classdecorator(decorator):
def inner(f):
if isinstance(f, types.FunctionType):
return decorator(f)
else:
f.__call__ = decorator(f.__call__)
return f
return inner
@classdecorator(memoize)
@composable
def double(n):
return n*2
(double * sum)([1, 2]) # => works
The second is to use libraries whose decorators have already undergone this operation (to support classes masquerading as functions). The toolz folks might allow that functionality addition.
Special
@composable
decorator to bring new functionality to function:The text was updated successfully, but these errors were encountered: