base: Make the Python module loader PEP302 compliant
Review Request #1857 - Created May 1, 2013 and submitted
Changeset 9688:349fa0e3e253 --------------------------- base: Make the Python module loader PEP302 compliant The custom Python loader doesn't comply with PEP302 for two reasons: * Previously, we would overwrite old modules on name conflicts. PEP302 explicitly states that: "If there is an existing module object named 'fullname' in sys.modules, the loader must use that existing module". * The "__package__" attribute wasn't set. PEP302: "The __package__ attribute must be set." This changeset addresses both of these issues.
Quick regressions pass (with the exception of 02.insttest and 40.m5threads-test-atomic where I can't find the binaries) for all supported architectures.
Posted (May 2, 2013, 1:22 a.m.)
Looks good. I'm curious, were there any bugs caused by this?
I'd say don't call imp.new_module unless you actually fail to find the module (Python evaluates all arguments to a function before the function is called, so the new module is created with setdefault): try: mod = sys.modules[fullname] except KeyError: mod = imp.new_module(fullname) sys.modules[fullname] = mod