In our latest release, POP 25.0.0, we've made a single significant update to stay in line with the future of Python: the switch from using "load_module" to "exec_module." While this might seem like a small shift, it ensures we are ready for Python 3.12's impending arrival.
As Python 3.11 rolls out, starting a POP application throws a logged warning indicating the imminent deprecation of "load_module." The suggestion? To start using "exec_module" instead. With POP 25, that warning is a thing of the past. The update ensures compatibility across all Python versions and prepares us for Python 3.12.
While Python 3.12 isn't officially supported by POP yet, we're laying the groundwork to ensure a seamless transition once it arrives. For now, we can say goodbye to that nagging warning.
Here are the critical lines of code that changed between POP 24.0.1 and 25.0.0:
def python(modname: str, path: str) -> "LoadedMod" or LoadError:
"""
Attempt to load the named python modules
:param modname: The name of the module to get from the loader
:param path: The package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
if modname in sys.modules:
return sys.modules[modname]
try:
- sfl = importlib.machinery.SourceFileLoader(modname, path)
- return sfl.load_module()
+ spec = importlib.util.spec_from_file_location(modname, path)
+ module = importlib.util.module_from_spec(spec)
+ sys.modules[modname] = module
+ module.__file__ = path
+ spec.loader.exec_module(module)
+ return module
except Exception as exc: # pylint: disable=broad-except
return LoadError(
f"Failed to load python module {modname} at path {path}",
exception=exc,
traceback=stdlib_traceback.format_exc(),
)
Even though it was only one update, due to its impact on the critical functionality of adding Python modules to the hub, we've bumped the major version number. But, rest assured, POP 25.0.0 is backward compatible with previous versions. We look forward to the future of Python and continue to adapt to meet its changes head-on.
Comments