Skip to content

Instantly share code, notes, and snippets.

@taitep
Created September 21, 2024 06:58
Show Gist options
  • Save taitep/03d668b9d66131bfabba9bd9ff7d643c to your computer and use it in GitHub Desktop.
Save taitep/03d668b9d66131bfabba9bd9ff7d643c to your computer and use it in GitHub Desktop.
Python decorator making it simple to create decorators with arguments
def arg_decorator(func):
def wrapper(*args, **kwargs):
return lambda f: func(f, *args, **kwargs)
return wrapper
@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