I have been experimenting with different kinds of decorators in Python and I am finding it difficult to understand Parameterized decorators. A decorator accepts callables and returns callable (callable being a function in my case) In the following code:-
def check_non_negative(index):
def validator(f):
def wrap(*args):
if args[index]<0:
raise ValueError(
'Argument {} must be non negative.'.format(index))
return f(*args)
return wrap
return validator
@check_non_negative(1)
def create_list(value,size):
return [value]*size
create_list('a',3)
Here I see that check_non_negative is not a decorator according to the definition but behaves like one (During run Validator is the actual decorator). check_non_negative takes an integer and not a callable, yet it behaves like decorator. Can somebody explain why?