[Python-checkins] r53629 - sandbox/trunk/import_in_py/importlib.py sandbox/trunk/import_in_py/test_importlib.py

brett.cannon python-checkins at python.org
Sat Feb 3 23:08:13 CET 2007


Author: brett.cannon
Date: Sat Feb  3 23:08:12 2007
New Revision: 53629

Modified:
   sandbox/trunk/import_in_py/importlib.py
   sandbox/trunk/import_in_py/test_importlib.py
Log:
Make the built-in and frozen module meta_path objects not use classmethods.


Modified: sandbox/trunk/import_in_py/importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/importlib.py	(original)
+++ sandbox/trunk/import_in_py/importlib.py	Sat Feb  3 23:08:12 2007
@@ -158,22 +158,19 @@
 
     """Base class for meta_path importers for built-in and frozen modules.
 
-    Subclasses must provide the _find and _load methods.  The methods are
-    expected to be defined on the subclass itself and not on an instance.
+    Subclasses must provide the _find and _load methods.
 
     """
 
-    @classmethod
-    def find_module(cls, fullname, path=None):
+    def find_module(self, fullname, path=None):
         """See if a built-in or frozen module can be imported based on the
         specified name."""
-        if cls._find(fullname):
-            return cls
+        if self._find(fullname):
+            return self
         else:
             return None
 
-    @classmethod
-    def load_module(cls, fullname):
+    def load_module(self, fullname):
         """Load a built-in or frozen module.
 
         'imp' code for loading a built-in or frozen module handles the setting
@@ -184,7 +181,7 @@
         try:
             return sys.modules[fullname]
         except KeyError:
-            mod = cls._load(fullname)
+            mod = self._load(fullname)
             if not mod:
                 raise ImportError("expected built-in module not loaded")
             return mod
@@ -605,7 +602,7 @@
     """
 
     def __init__(self, default_path_hook=None,
-                 extended_meta_path=(BuiltinImporter, FrozenImporter)):
+                 extended_meta_path=(BuiltinImporter(), FrozenImporter())):
         """Store a default path hook entry and a sequence to internally extend
         sys.meta_path by."""
         self.extended_meta_path = extended_meta_path

Modified: sandbox/trunk/import_in_py/test_importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/test_importlib.py	(original)
+++ sandbox/trunk/import_in_py/test_importlib.py	Sat Feb  3 23:08:12 2007
@@ -85,7 +85,7 @@
 
     """Test the built-in module importer."""
 
-    importer = importlib.BuiltinImporter
+    importer = importlib.BuiltinImporter()
     module_name = 'sys'
     bad_module_names = ('tokenize', 'time', '__hello__')
 
@@ -100,7 +100,7 @@
     
     """
 
-    importer = importlib.FrozenImporter
+    importer = importlib.FrozenImporter()
     module_name = '__hello__'
     bad_module_names = ('tokenize', 'time', 'sys')
 


More information about the Python-checkins mailing list