Skip to content

Instantly share code, notes, and snippets.

@jymchng
Created August 20, 2022 13:39
Show Gist options
  • Save jymchng/add25bcd5cfc7fe1f7f2c798786f2953 to your computer and use it in GitHub Desktop.
Save jymchng/add25bcd5cfc7fe1f7f2c798786f2953 to your computer and use it in GitHub Desktop.
Make partial out from a function.
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