New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add decorator for make functions partial applicable #59888
Comments
I am not sure if this is the right way to do it but IMHO it would be great to from functools import partial
class partial_applicable():
def __call__(self, func):
def __wrapper(*args, **kvargs):
try:
return func(*args, **kvargs)
except TypeError:
return partial(func, *args, **kvargs)
return __wrapper Then you could do like: @partial_applicable()
def substract(left, right):
return left - right
substract(10, 100)
=> -90
rclose = substract(right = 1000)
=> rclose(10) => -990
lclose = substract(1)
=> lclose(10) => -9 What do you think? |
Or maybe even class partial_applicable():
def __call__(self, func):
def __wrapper(*args, **kvargs):
try:
return func(*args, **kvargs)
except TypeError:
partial_func = partial(func, *args, **kvargs)
return partial_applicable()(partial_func)
return __wrapper |
YAGNI, is what I think. Or if you do need it, put it in your application. (To tell you the truth, it just looks confusing to me...it strikes me as too magical.) Regardless, this is more of a python-ideas kind of issue, so I suggest raising it there if you want to pursue it. |
Thanks for your feedback. |
Thanks for your suggestion, even though I'm rejecting the suggestion as a bug tracker issue. (I should have said that at the start of my answer.) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: