def partial_decorator func def wrap wargs wkwargs if hasattr func args

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def partial_decorator(func):
def wrap(*wargs, **wkwargs):
if hasattr(func, 'args'):
num = func.args
else:
num = 0
if len(wargs) >= max(len(inspect.getargspec(func).args), num):
return func(*wargs, **wkwargs)
else:
def prtfunc(*pargs, **pkwargs):
k = dict(wkwargs)
k.update(pkwargs)
return func(*(wargs+pargs), **(k))
prtfunc.args = func.func_code.co_argcount
return partial_decorator(prtfunc)
return wrap