diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2012-07-20 13:40:09 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2012-07-20 13:40:09 (GMT) |
commit | be7e49fd820318509cd8b4dbde479c552f74ef62 (patch) | |
tree | 856c3693092233495f1ecadbd90c0b7e085cc70d /Lib/importlib | |
parent | 818b1186f9459646a4ad7015ed45ce9dfea0fa55 (diff) | |
download | cpython-be7e49fd820318509cd8b4dbde479c552f74ef62.zip cpython-be7e49fd820318509cd8b4dbde479c552f74ef62.tar.gz cpython-be7e49fd820318509cd8b4dbde479c552f74ef62.tar.bz2 |
Close #15386: There was a loophole that meant importlib.machinery and imp would sometimes reference an uninitialised copy of importlib._bootstrap
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/__init__.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 0935ada..d30691a 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -2,14 +2,21 @@ __all__ = ['__import__', 'import_module', 'invalidate_caches'] # Bootstrap help ##################################################### -import imp + +# Until bootstrapping is complete, DO NOT import any modules that attempt +# to import importlib._bootstrap (directly or indirectly). Since this +# partially initialised package would be present in sys.modules, those +# modules would get an uninitialised copy of the source version, instead +# of a fully initialised version (either the frozen one or the one +# initialised below if the frozen one is not available). +import _imp # Just the builtin component, NOT the full Python module import sys try: import _frozen_importlib as _bootstrap except ImportError: from . import _bootstrap - _bootstrap._setup(sys, imp) + _bootstrap._setup(sys, _imp) else: # importlib._bootstrap is the built-in import, ensure we don't create # a second copy of the module. @@ -22,6 +29,8 @@ else: _w_long = _bootstrap._w_long _r_long = _bootstrap._r_long +# Fully bootstrapped at this point, import whatever you like, circular +# dependencies and startup overhead minimisation permitting :) # Public API ######################################################### |