Created
August 15, 2021 19:43
-
-
Save onelharrison/e1a9e32596230b68b3c861b50c156f02 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def log_before(f): | |
def _wrapper(*args, **kwargs): | |
print("logging before...") | |
f(*args, **kwargs) | |
return _wrapper | |
def log_after(f): | |
def _wrapper(*args, **kwargs): | |
f(*args, **kwargs) | |
print("logging after...") | |
return _wrapper | |
@log_before | |
@log_after | |
def greet(name: str): | |
print(f"Hello {name}") | |
# with the log_before and log_after decorators | |
# the following is semantically equivalent to | |
# `log_before(log_after(greet))("John")` | |
greet("John") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment