The global dictionary of rab
is baked in. You can see it at rab.func_globals
.
The attribute is readonly, so you can't replace it
You can make a new function in foo
and push the code from rab
into it though :)
type(rab)(rab.func_code, foo.__dict__)
eg.
## rab.py
import foo
foo.bar()
# expected to return and it does
foo.check(5)
print 'bar: ok'
def rab():
global a
a = 6
foo.rab = type(rab)(rab.func_code, foo.__dict__)
foo.rab()
# may be expected to return but it raises AssertionError:
foo.check(6)
print 'rab: ok'
But don't do it