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
I have a use case where I pass to a function function func1 another function func2 as input, and then inside the function func1, new arguments are prepared and calling func2 with these new arguments... as this function func2 could be one of many it is not very practical to add decorator for each option but instead I would like to apply wrapper inside func1...
A demonstration is:
fromfunctoolsimportwraps, partialdefmy_decorator(f):
@wraps(f)defwrapper(*args, **kwds):
print('Calling decorated function')
returnf(*args, **kwds)
returnwrapper# @my_decoratordefexample(a, b=2):
"""Docstring"""print('Called example function with arguments:', a, b)
my_decorator(example)(1)
# example.__name__# example.__doc__example_=partial(example, b=4)
my_decorator(example_)(1)
It is related to my work on Lightning-AI/torchmetrics#2335 where some functions can have implementation inside test, some would be coming straight from sklearn and some would be with functools.partial
The text was updated successfully, but these errors were encountered:
Ok. Nice. That's a valid use case.
Definitely would be cool to support this, as long as nothing else breaks, slows down or becomes more complex to maintain.
fromfunctoolsimportpartialfromcachierimportcachierdefexample(a, b=2):
"""Docstring"""print('Called example function with arguments:', a, b)
cachier()(example)(1)
# example.__name__# example.__doc__example_=partial(example, b=4)
cachier()(example_)(1)
I have a use case where I pass to a function function
func1
another functionfunc2
as input, and then inside the functionfunc1
, new arguments are prepared and callingfunc2
with these new arguments... as this functionfunc2
could be one of many it is not very practical to add decorator for each option but instead I would like to apply wrapper insidefunc1
...A demonstration is:
It is related to my work on Lightning-AI/torchmetrics#2335 where some functions can have implementation inside test, some would be coming straight from
sklearn
and some would be withfunctools.partial
The text was updated successfully, but these errors were encountered: