exec() function is currently quite clear on which types are accepted or not: exact dict for globals, mapping for locals.
* "If only globals is provided, it must be a dictionary (and not a subclass of dictionary), which will be used for both the global and the local variables."
* "If provided, locals can be any mapping object."
Moreover, the requirement on the exact dict type allowed to implement an optimization on globals in Python 3.8:
"LOAD_GLOBAL instruction now uses new “per opcode cache” mechanism. It is about 40% faster now. (Contributed by Yury Selivanov and Inada Naoki in bpo-26219.)" |