]> granicus.if.org Git - python/commitdiff
Tweak the handling of the empty string in sys.path for importlib.
authorBrett Cannon <brett@python.org>
Thu, 16 Feb 2012 23:12:00 +0000 (18:12 -0500)
committerBrett Cannon <brett@python.org>
Thu, 16 Feb 2012 23:12:00 +0000 (18:12 -0500)
It seems better to cache the finder for the cwd under its full path
insetad of '' in case the cwd changes. Otherwise FileFinder needs to
dynamically change itself based on whether it is given '' instead of
caching a finder for every change to the cwd.

Lib/importlib/_bootstrap.py
Lib/importlib/test/import_/test_path.py

index 44349a8e1287a2e0b6ea2e031d88017c72db92be..39cf76a3106c3f67b64f2e6bcbd38600d8ec0a79 100644 (file)
@@ -713,10 +713,12 @@ class PathFinder:
         the default hook, for which ImportError is raised.
 
         """
+        if path == '':
+            path = _os.getcwd()
         try:
             finder = sys.path_importer_cache[path]
         except KeyError:
-            finder = cls._path_hooks(path if path != '' else _os.getcwd())
+            finder = cls._path_hooks(path)
             sys.path_importer_cache[path] = finder
         else:
             if finder is None and default:
index b28f25df869e8a5d6d66874ff9d1e61749caefd3..61fe2260d4f2458ff4be86ef58d1a2292de82521 100644 (file)
@@ -82,7 +82,7 @@ class FinderTests(unittest.TestCase):
         with util.import_state(path=[path], path_hooks=[hook]):
             loader = machinery.PathFinder.find_module(module)
             self.assertIs(loader, importer)
-            self.assertIn('', sys.path_importer_cache)
+            self.assertIn(os.getcwd(), sys.path_importer_cache)
 
 
 class DefaultPathFinderTests(unittest.TestCase):