I'm trying to figure out why i need a one more nested function when using decorators. Here is an example:
def func(f):
def deco(*args, **kwargs):
return f(*args, **kwargs)
return deco
@func
def sum(a, b):
return a+b
print sum(5, 10)
Code works, everything is fine. But why do i need to create nested "deco" function? Let's try without it:
def func(f):
return f(*args, **kwargs)
@func
def sum(a, b):
return a+b
print sum(5, 10)
Code fails.
So there are three questions:
- Why second sample does not works?
- Why args,kwargs are "magically" appears if we are using a nested function?
- What can i do, to make 2nd sample work? Except nesting another function, ofcourse.