I am using setattr() to monkey patch a closure. Using getattr() shows that the closure was patched correctly. However, the return value is unaffected.
>>> def foo():
... def bar():
... return('bar')
... return(bar())
...
>>> def baz():
... return('baz')
...
>>> setattr(foo, 'bar', baz)
>>> bar = getattr(foo, 'bar')
>>> bar()
'baz'
>>> foo()
'bar'
After using setattr() I expect foo() to return 'baz';
but, it returns 'bar' as if the patch never happened.