@adds_dynamic_z_decorator
def func(x, y):
    print(z)

def other_recurse(x):
    global z
print('x=%s, z=%s' % (x, z))
recurse(x + 1)
print('x=%s, z=%s' % (x, z))

@adds_dynamic_z_decorator
def recurse(x=0):
    global z
z = x
if x < 3:
    other_recurse(x)
print('calling func(1,2)')
func(1, 2)
print('calling recurse()')
recurse()
Can I use a decorator to mutate the local scope of a function in Python?