-
-
Save taitep/03d668b9d66131bfabba9bd9ff7d643c to your computer and use it in GitHub Desktop.
Python decorator making it simple to create decorators with arguments
This file contains 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 arg_decorator(func): | |
def wrapper(*args, **kwargs): | |
return lambda f: func(f, *args, **kwargs) | |
return wrapper |
This file contains 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
@arg_decorator | |
def decorator(func, a, b=None): # function to decorate has to be first argument | |
def wrapper(*args, **kwargs): | |
if b is not None: | |
print(b) | |
return func(*args, **kwargs) + a | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment