Skip to content

Instantly share code, notes, and snippets.

@onelharrison
Created August 15, 2021 19:43
Show Gist options
  • Save onelharrison/e1a9e32596230b68b3c861b50c156f02 to your computer and use it in GitHub Desktop.
Save onelharrison/e1a9e32596230b68b3c861b50c156f02 to your computer and use it in GitHub Desktop.
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