constraint_parameters(func, constraint_list=['has', 'is', 'are']):
def wrap_func(*params):
if len(params) == 1 and params[0] in constraint_list:
func(*params)
else:
raise Exception("Y U NO FOLLOW CONSTRAINTS?")
return wrap_func
@constraint_parameters
def hello(val):
print(val)
hello('is') # prints is
hello('test') # Exception: Y U NO FOLLOW CONSTRAINTS?
^ edited to guard against more than one parameters
🤣
:D you have to have fun
Обсуждают сегодня