[Python-checkins] cpython: Make it more obvious what things used in imp are snuck in through private APIs

brett.cannon python-checkins at python.org
Sat Jun 15 04:30:07 CEST 2013


http://hg.python.org/cpython/rev/7bb54aa762e1
changeset:   84135:7bb54aa762e1
user:        Brett Cannon <brett at python.org>
date:        Fri Jun 14 22:29:58 2013 -0400
summary:
  Make it more obvious what things used in imp are snuck in through private APIs

files:
  Lib/imp.py |  19 ++++++++-----------
  1 files changed, 8 insertions(+), 11 deletions(-)


diff --git a/Lib/imp.py b/Lib/imp.py
--- a/Lib/imp.py
+++ b/Lib/imp.py
@@ -16,11 +16,9 @@
     # Platform doesn't support dynamic loading.
     load_dynamic = None
 
-# Directly exposed by this module
-from importlib._bootstrap import cache_from_source, source_from_cache
+from importlib._bootstrap import (cache_from_source, source_from_cache,
+                                  SourcelessFileLoader, _ERR_MSG)
 
-
-from importlib import _bootstrap
 from importlib import machinery
 from importlib import util
 import importlib
@@ -117,7 +115,7 @@
             return super().get_data(path)
 
 
-class _LoadSourceCompatibility(_HackedGetData, _bootstrap.SourceFileLoader):
+class _LoadSourceCompatibility(_HackedGetData, machinery.SourceFileLoader):
 
     """Compatibility support for implementing load_source()."""
 
@@ -131,12 +129,11 @@
     module = sys.modules[name]
     # To allow reloading to potentially work, use a non-hacked loader which
     # won't rely on a now-closed file object.
-    module.__loader__ = _bootstrap.SourceFileLoader(name, pathname)
+    module.__loader__ = machinery.SourceFileLoader(name, pathname)
     return module
 
 
-class _LoadCompiledCompatibility(_HackedGetData,
-        _bootstrap.SourcelessFileLoader):
+class _LoadCompiledCompatibility(_HackedGetData, SourcelessFileLoader):
 
     """Compatibility support for implementing load_compiled()."""
 
@@ -150,7 +147,7 @@
     module = sys.modules[name]
     # To allow reloading to potentially work, use a non-hacked loader which
     # won't rely on a now-closed file object.
-    module.__loader__ = _bootstrap.SourcelessFileLoader(name, pathname)
+    module.__loader__ = SourcelessFileLoader(name, pathname)
     return module
 
 
@@ -168,7 +165,7 @@
                 break
         else:
             raise ValueError('{!r} is not a package'.format(path))
-    return _bootstrap.SourceFileLoader(name, path).load_module(name)
+    return machinery.SourceFileLoader(name, path).load_module(name)
 
 
 def load_module(name, file, filename, details):
@@ -252,7 +249,7 @@
                 continue
             break  # Break out of outer loop when breaking out of inner loop.
     else:
-        raise ImportError(_bootstrap._ERR_MSG.format(name), name=name)
+        raise ImportError(_ERR_MSG.format(name), name=name)
 
     encoding = None
     if mode == 'U':

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list