[New-bugs-announce] [issue45659] Add FrozenImporter.get_filename().
Eric Snow
report at bugs.python.org
Thu Oct 28 14:52:00 EDT 2021
New submission from Eric Snow <ericsnowcurrently at gmail.com>:
Now that __file__ is set on frozen (stdlib) modules, we can add an implementation for FrozenImporter.get_filename(). This would make FrozenImporter and implementation of ExecutionLoader. [1]
There is a caveat: in spec_from_loader() [2] we infer the presence of get_filename() to mean the loader is file-based, which FrozenImporter isn't.
In that case we call spec_from_file_location() [3], which should not be used for frozen modules. Most importantly, spec.origin for frozen modules should remain "frozen", spec.cached should remain None, and spec.has_location should remain False. That's because the module was imported frozen and not from a file (even though it originated in a file).
[1] https://docs.python.org/3/library/importlib.html#importlib.abc.ExecutionLoader
[2] in Lib/import/_bootstrap.py
[3] in Lib/import/_bootstrap_external.py
----------
components: Library (Lib)
messages: 405225
nosy: FFY00, eric.snow
priority: normal
severity: normal
stage: needs patch
status: open
title: Add FrozenImporter.get_filename().
type: behavior
versions: Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45659>
_______________________________________
More information about the New-bugs-announce
mailing list