I'm going over decorators with this page (scroll down to section 9) and the two examples work fine. However, I don't like how nested functions are used. It seems like a lot of extra effort for such a simple task. For the first example, using the outer() and inner() functions, I can't simply comment out inner like so
def outer(some_func):
# def inner():
print("before some_func")
ret = some_func() # 1
return ret + 1
# return inner
def foo():
return 1
decorated = outer(foo) # 2
print(decorated())
because Python gives
TypeError: 'int' object is not callable
on the print(decorated()) line.
I'm not sure what's going on here. Is there any way to rewrite this decorator without needing to use two nested functions? I'd also like to see if the second example, using coordinate pairs and the wrapper() and checker() functions can also be rewritten to avoid the extra function.