bpo-45324: Capture data in FrozenImporter.find_spec() to use in exec_module(). by ericsnowcurrently · Pull Request #28633 · python/cpython
Currently we end up duplicating effort and throwing away data in FrozenImporter.find_spec(). With this change we do the work once in find_spec() and the only thing we do in FrozenImporter.exec_module() is turn the raw frozen data into a code object and then exec it.
The change involves adding _imp.find_frozen(), adding an arg to _imp.get_frozen_object(), and updating FrozenImporter. We also move some code around to reduce some duplication, get a little more consistency in outcomes, and be more efficient.
Note that this change is mostly necessary if we want to set __file__ on frozen stdlib modules. (See https://bugs.python.org/issue21736.)