[Python-checkins] cpython: Issue #19703: Update pydoc to use the new importer APIs.

eric.snow python-checkins at python.org
Tue Jan 7 04:51:09 CET 2014


http://hg.python.org/cpython/rev/f67ccb4490ea
changeset:   88331:f67ccb4490ea
user:        Eric Snow <ericsnowcurrently at gmail.com>
date:        Mon Jan 06 20:42:59 2014 -0700
summary:
  Issue #19703: Update pydoc to use the new importer APIs.

files:
  Lib/pydoc.py           |  17 +++++++++++++----
  Lib/test/test_pydoc.py |   2 ++
  Misc/NEWS              |   2 ++
  3 files changed, 17 insertions(+), 4 deletions(-)


diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -246,8 +246,12 @@
         else:
             # Must be a binary module, which has to be imported.
             loader = loader_cls('__temp__', filename)
+            # XXX We probably don't need to pass in the loader here.
+            spec = importlib.util.spec_from_file_location('__temp__', filename,
+                                                          loader=loader)
+            _spec = importlib._bootstrap._SpecMethods(spec)
             try:
-                module = loader.load_module('__temp__')
+                module = _spec.load()
             except:
                 return None
             del sys.modules['__temp__']
@@ -277,8 +281,11 @@
         loader = importlib._bootstrap.SourcelessFileLoader(name, path)
     else:
         loader = importlib._bootstrap.SourceFileLoader(name, path)
+    # XXX We probably don't need to pass in the loader here.
+    spec = importlib.util.spec_from_file_location(name, path, loader=loader)
+    _spec = importlib._bootstrap._SpecMethods(spec)
     try:
-        return loader.load_module(name)
+        return _spec.load()
     except:
         raise ErrorDuringImport(path, sys.exc_info())
 
@@ -2008,10 +2015,11 @@
                 callback(None, modname, '')
             else:
                 try:
-                    loader = importer.find_module(modname)
+                    spec = pkgutil._get_spec(importer, modname)
                 except SyntaxError:
                     # raised by tests for bad coding cookies or BOM
                     continue
+                loader = spec.loader
                 if hasattr(loader, 'get_source'):
                     try:
                         source = loader.get_source(modname)
@@ -2025,8 +2033,9 @@
                     else:
                         path = None
                 else:
+                    _spec = importlib._bootstrap._SpecMethods(spec)
                     try:
-                        module = loader.load_module(modname)
+                        module = _spec.load()
                     except ImportError:
                         if onerror:
                             onerror(modname)
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -649,8 +649,10 @@
     def test_importfile(self):
         loaded_pydoc = pydoc.importfile(pydoc.__file__)
 
+        self.assertIsNot(loaded_pydoc, pydoc)
         self.assertEqual(loaded_pydoc.__name__, 'pydoc')
         self.assertEqual(loaded_pydoc.__file__, pydoc.__file__)
+        self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__)
 
 
 class TestDescriptions(unittest.TestCase):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -287,6 +287,8 @@
 
 - Issue #19708: Update pkgutil to use the new importer APIs.
 
+- Issue #19703: Update pydoc to use the new importer APIs.
+
 - Issue #19851: Fixed a regression in reloading sub-modules.
 
 - ssl.create_default_context() sets OP_NO_COMPRESSION to prevent CRIME.

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


More information about the Python-checkins mailing list