Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Last active January 26, 2022 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbnorth/42da3a3ebf4ce36e7a4b196dc0c9d0c9 to your computer and use it in GitHub Desktop.
Save tbnorth/42da3a3ebf4ce36e7a4b196dc0c9d0c9 to your computer and use it in GitHub Desktop.
Possibly useless partial / delayed execution Python experiment
from functools import partial, wraps, update_wrapper
from time import sleep
def partialize(func):
@wraps(func)
def _partial(*args, **kwargs):
part = partial(func, *args, **kwargs)
update_wrapper(part, func)
return part
return _partial
@partialize
def adder(a, b):
"""Not the snake"""
sleep(5)
return a + b
later = adder(2, 40)
print(adder(2, 2))
print(later())
print(later.__doc__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment