Skip to content

Instantly share code, notes, and snippets.

@tmr232
Created March 15, 2022 08:57
Show Gist options
  • Save tmr232/225e3468a47c53b31702d4c93e9a98b9 to your computer and use it in GitHub Desktop.
Save tmr232/225e3468a47c53b31702d4c93e9a98b9 to your computer and use it in GitHub Desktop.
Demonstration of decorator-abuse!
"""
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