Created
July 12, 2020 09:50
-
-
Save rec/89c4e38cc6447bf324c9d63af7d548ad 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
# 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