Created
March 15, 2022 08:57
-
-
Save tmr232/225e3468a47c53b31702d4c93e9a98b9 to your computer and use it in GitHub Desktop.
Demonstration of decorator-abuse!
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
""" | |
Relevant PEPs: | |
- https://peps.python.org/pep-0572/ | |
- https://peps.python.org/pep-0614/ | |
""" | |
from functools import wraps | |
@lambda f: ( | |
wrapper := lambda *args, **kwargs: ( | |
print(f"Enter {f.__name__}"), | |
ret := f(*args, **kwargs), | |
print(f"Exit {f.__name__}"), | |
ret | |
)[-1], | |
wraps(f)(wrapper) | |
)[-1] | |
def x(n): | |
print(n) | |
x(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment