[pypy-svn] r70186 - in pypy/branch/import-builtin/pypy: interpreter module/imp module/imp/test

afa at codespeak.net afa at codespeak.net
Fri Dec 18 00:12:51 CET 2009


Author: afa
Date: Fri Dec 18 00:12:50 2009
New Revision: 70186

Modified:
   pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py
   pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py
   pypy/branch/import-builtin/pypy/module/imp/importing.py
   pypy/branch/import-builtin/pypy/module/imp/test/test_import.py
Log:
Test and fix for the previous checkin

Modified: pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py	Fri Dec 18 00:12:50 2009
@@ -349,14 +349,17 @@
         self.builtin_modules[name] = w_mod
         return name
 
-    def getbuiltinmodule(self, name):
+    def getbuiltinmodule(self, name, force_init=False):
         w_name = self.wrap(name)
         w_modules = self.sys.get('modules')
         try:
-            return self.getitem(w_modules, w_name)
+            w_mod = self.getitem(w_modules, w_name)
         except OperationError, e:
             if not e.match(self, self.w_KeyError):
                 raise
+        else:
+            if not force_init:
+                return w_mod
 
         # If the module is a builtin but not yet imported,
         # retrieve it and initialize it

Modified: pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py
==============================================================================
--- pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py	(original)
+++ pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py	Fri Dec 18 00:12:50 2009
@@ -90,11 +90,12 @@
             for name in self.loaders: 
                 w_value = self.get(name)  
                 space.setitem(self.w_dict, space.new_interned_str(name), w_value) 
-            self.lazy = False 
+            self.lazy = False
+            self.w_initialdict = space.call_method(self.w_dict, 'items')
         return self.w_dict 
 
     def _freeze_(self):
-        self.w_initialdict = self.space.call_method(self.getdict(), 'copy')
+        self.getdict()
         self.startup_called = False
         # hint for the annotator: Modules can hold state, so they are
         # not constant

Modified: pypy/branch/import-builtin/pypy/module/imp/importing.py
==============================================================================
--- pypy/branch/import-builtin/pypy/module/imp/importing.py	(original)
+++ pypy/branch/import-builtin/pypy/module/imp/importing.py	Fri Dec 18 00:12:50 2009
@@ -330,7 +330,7 @@
         return space.call_method(find_info.w_loader, "load_module", w_modulename)
 
     if find_info.modtype == C_BUILTIN:
-        return space.getbuiltinmodule(find_info.filename)
+        return space.getbuiltinmodule(find_info.filename, force_init=True)
 
     if find_info.modtype in (PY_SOURCE, PY_COMPILED, PKG_DIRECTORY):
         if reuse:

Modified: pypy/branch/import-builtin/pypy/module/imp/test/test_import.py
==============================================================================
--- pypy/branch/import-builtin/pypy/module/imp/test/test_import.py	(original)
+++ pypy/branch/import-builtin/pypy/module/imp/test/test_import.py	Fri Dec 18 00:12:50 2009
@@ -431,6 +431,15 @@
         import pkg.a
         reload(pkg.a)
 
+    def test_reload_builtin(self):
+        import sys
+        try:
+            del sys.setdefaultencoding
+        except AttributeError:
+            pass
+        reload(sys)
+        assert 'setdefaultencoding' in dir(sys)
+
 def _getlong(data):
     x = marshal.dumps(data)
     return x[-4:]



More information about the Pypy-commit mailing list