Turns out the answer was there all the time in docs :
If two separate objects are specified as global and local, the code will be executed as if it were embedded in the class definition.
Since I pass both globals and locals , it runs as if it were in a class.
class Foo(object): foo = [1,2,3] @staticmethod def bar(): return foo[1]
not surprisingly not working :).
For anyone interested in a workaround, you can insert namespace back into namespace['bar'].func_globals 1 ( inspired by this ):
>>> namespace['bar'].func_globals.update(namespace) >>> namespace['bar']() 2
Nice.
1 This will be namespace['bar'].__globals__.update in python3.x
source share