py: Optimize locals()/globals() implementation.