[issue21736] Add __file__ attribute to frozen modules

Guido van Rossum report at bugs.python.org
Wed Sep 15 17:07:12 EDT 2021


Guido van Rossum <guido at python.org> added the comment:

> Note that the filename information is already available in the
> code object's co_filename attribute.

Hm, in the latest (3.11) main that's not true -- co_filename is set to something like "<frozen ntpath>". And that's about right, since the filename contained in the frozen data can at best reflect the filename at the time the freeze script ran, which is not necessarily the same as the filename when the user runs the Python binary.

I don't think we should try to set __file__ or any other attributes on frozen modules (at least not for the small set of frozen modules we're contemplating for 3.11).  User who need the file can run their Python 3.11 binary with -Xfrozen_modules=off, to disable the use of frozen modules (other than the three importlib bootstrap files).

Tools that freeze the entire stdlib or 3rd party code may have to make a  different choice, but that's not our problem (yet).

----------

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


More information about the Python-bugs-list mailing list