[issue14657] Avoid two importlib copies
report at bugs.python.org
Mon May 7 08:50:04 CEST 2012
Nick Coghlan <ncoghlan at gmail.com> added the comment:
In that case, how about we go with:
1. By default, importlib._bootstrap is never imported. Instead, it is set to be a reference to _frozen_importlib. However, _frozen_importlib does *not* lie about where it came from (and doesn't assume the on-disk source matches the frozen source).
2. We provide two private functions in importlib.__init__: one that replaces all _frozen_importlib references in the import state with importlib._bootstrap references (retrieving the latter from disk first), and one that reverses the process.
Note that the __import__ builtin should be replaced as well, since that will otherwise call in to the frozen version of the module.
This is basically the same as Eric Snow's suggestion, just with most of the nuts and bolts kept within importlib, so that the testing context manager doesn't need to know the details - it can just call the appropriate importlib functions to change the active implementation.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list