Names are resolved lexically. Just because you call a function named fib
from within a function named fib
, that doesn't mean it would necessarilly be the same fib
.
A (highly inaccurate) demonstration of what's going on is this:
def fib(n):
return n if n in (0, 1) else globals()['fib'](n-1) + globals()['fib'](n-2)
Since the decorater affects globals
, you get the decorated fib
at the time the recursive call occurs.