-
Notifications
You must be signed in to change notification settings - Fork 267
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 functoolz.reorder_args #546
base: master
Are you sure you want to change the base?
Conversation
Apparently the .replace method on code objects wasn't introduced till Python 3.8. Code objects have readonly attributes though, so I need to figure out a workaround for updating the wrapper function name. |
@eriknw The test failures I think are caused by the linter. This is ready to look over though. |
I have also reached for and missed a 'reorder' function, especially when dealing with some of the dicttoolz functionality like
def reorder(f, ordering):
def inner(*args, **kwargs):
return f(*[args[i] for i in ordering], **kwargs)
return inner
def reorder(f, ordering):
# handle the case of incomplete specification by assuming flips, e.g. {2:1} requires a corresponding {1:2}
complete_ordering = merge(dict(map(reverse, ordering.items())), ordering)
def inner(*args, **kwargs):
return f(*[args[get_in(complete_ordering, [i], default=i)] for i in range(len(args))], **kwargs)
return inner |
Candidate function to reorder arguments of an existing function.
Allows alternative function signatures that might be more useful to curry. The wrapped function name reflects the argument remapping for easier debugging.