Created
August 20, 2022 13:39
-
-
Save jymchng/add25bcd5cfc7fe1f7f2c798786f2953 to your computer and use it in GitHub Desktop.
Make partial out from a function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _partial(func, *args, **keywords): | |
@wraps(func) # functools.wraps doesn't wrap func, so add it here | |
def newfunc(*fargs, **fkeywords): | |
newkeywords = {**keywords, **fkeywords} | |
return func(*args, *fargs, **newkeywords) | |
newfunc.func = func | |
newfunc.args = args | |
newfunc.keywords = keywords | |
return newfunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment