[issue45020] Freeze all modules imported during startup.

Gregory Szorc report at bugs.python.org
Wed Sep 22 22:27:46 EDT 2021


Gregory Szorc <gregory.szorc at gmail.com> added the comment:

I'll throw out that __file__ is strictly optional, per https://docs.python.org/3/reference/datamodel.html. IMO it is more important to define importlib.abc.InspectLoader than __file__ (so tracebacks have source context).

Given that __file__ is optional, I'll throw out the idea of shipping modules without __file__/__cached__ and see what issues/pushback occurs. I anticipate this will likely result in having to restore advertising __file__ in frozen modules in 3.11 due to popular demand. But we /could/ use this as an opportunity to start attempting to ween people off __file__ and onto more appropriate APIs, like importlib.resources. (importlib.resources was introduced in 3.7 and I'm not sure that's old enough to force people onto without relying on a shim like https://pypi.org/project/importlib-resources/.)

Alternatively, defining a path hook referencing the python executable that knows how to service frozen modules could also work. zipimporter does this (__file__ is <zip_path>/<virtual_module_path>) and it is surprisingly not as brittle as one would think. It might be a good middle ground.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45020>
_______________________________________


More information about the Python-bugs-list mailing list