Skip to content

Instantly share code, notes, and snippets.

@rec
Created July 12, 2020 09:50
Show Gist options
  • Save rec/89c4e38cc6447bf324c9d63af7d548ad to your computer and use it in GitHub Desktop.
Save rec/89c4e38cc6447bf324c9d63af7d548ad to your computer and use it in GitHub Desktop.
# Correct decorator for an optional parameter
def print_before4(label='label'):
def decorator(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
print(label, args, kwargs)
return func(*args, **kwargs)
return wrapped
if callable(label): # It's a simple decorator call
return decorator(label)
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment