Last active
January 26, 2022 20:52
-
-
Save tbnorth/42da3a3ebf4ce36e7a4b196dc0c9d0c9 to your computer and use it in GitHub Desktop.
Possibly useless partial / delayed execution Python experiment
This file contains 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
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