Created
July 22, 2016 14:22
-
-
Save inirudebwoy/ed64d849aed9e2b1c4b14daa10e054c8 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
def kwargs_default(params): | |
"""Decorator for setting default keyword parameters | |
@kwargs_default((('number_of_chickens', 3),)) | |
will add param 'number_of_chickens' with value of 3 into kwargs. | |
:param params: tuple of tuples consiting of name of parameter and value | |
:type params: tuple of tuples with str and any ((str, any), (str, any), ...) | |
""" | |
def decorate(func): | |
def wrapped(*args, **kwargs): | |
for name, value in params: | |
if name not in kwargs: | |
kwargs[name] = value | |
return func(*args, **kwargs) | |
return wrapped | |
return decorate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment