[Python-checkins] r52944 - sandbox/trunk/import_in_py/importer.py sandbox/trunk/import_in_py/test_importer.py
brett.cannon
python-checkins at python.org
Thu Dec 7 00:23:20 CET 2006
Author: brett.cannon
Date: Thu Dec 7 00:23:19 2006
New Revision: 52944
Modified:
sandbox/trunk/import_in_py/importer.py
sandbox/trunk/import_in_py/test_importer.py
Log:
Remove optimization for frozen modules and built-in modules where if 'path'
was set that then to not bother searching. Frozen packages have __path__
set and thus cause the argument to be passed in.
Modified: sandbox/trunk/import_in_py/importer.py
==============================================================================
--- sandbox/trunk/import_in_py/importer.py (original)
+++ sandbox/trunk/import_in_py/importer.py Thu Dec 7 00:23:19 2006
@@ -182,9 +182,7 @@
short-circuit if one is specified.
"""
- if path is not None:
- return None
- elif cls._find(fullname):
+ if cls._find(fullname):
return cls
else:
return None
@@ -198,8 +196,6 @@
that we do not need to perform that step as outlined by PEP 302.
"""
- if path is not None:
- raise TypeError("loader does not expect an argument for 'path'")
try:
return sys.modules[fullname]
except KeyError:
@@ -211,7 +207,12 @@
class BuiltinImporter(BuiltinFrozenBaseImporter):
- """sys.meta_path class for importing built-in modules."""
+ """sys.meta_path class for importing built-in modules.
+
+ XXX Possible optimization is to bail out in find_module() if 'path' is set
+ to a value. Also can then raise an error in load_module() if 'path' is set.
+
+ """
_find = imp.is_builtin
_load = imp.init_builtin
Modified: sandbox/trunk/import_in_py/test_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/test_importer.py (original)
+++ sandbox/trunk/import_in_py/test_importer.py Thu Dec 7 00:23:19 2006
@@ -46,11 +46,6 @@
self.failUnlessRaises(TypeError, self.importer.find_module,
self.module_name, None, None)
- def test_find_module_path_shortcut(self):
- # Test short-circuiting of finding a module if 'path' argument is given
- # a value.
- self.failUnless(not self.importer.find_module(self.module_name, ''))
-
def test_load_module_prev_import_check(self):
# If a module is already in sys.modules it should be returned without
# being re-initialized.
@@ -75,12 +70,6 @@
if mod:
sys.modules[self.module_name] = mod
-
- def test_load_module_no_path_argument(self):
- # TypeError should be raise if 'path' argument set.
- self.failUnlessRaises(TypeError, self.importer.load_module,
- self.module_name, '')
-
def test_load_module_ImportError(self):
self.failUnlessRaises(ImportError,
self.importer.load_module,
More information about the Python-checkins
mailing list