[pypy-svn] pypy default: Actually set the attribute for the submodule on the parent module, fixes both that and importing.

alex_gaynor commits-noreply at bitbucket.org
Fri Dec 31 00:50:20 CET 2010


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r40304:8baddb1318ac
Date: 2010-12-30 17:50 -0600
http://bitbucket.org/pypy/pypy/changeset/8baddb1318ac/

Log:	Actually set the attribute for the submodule on the parent module,
	fixes both that and importing.

diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py
--- a/pypy/interpreter/mixedmodule.py
+++ b/pypy/interpreter/mixedmodule.py
@@ -31,11 +31,13 @@
         space.builtin_modules"""
         Module.install(self)
         if hasattr(self, "submodules"):
-            name = self.space.unwrap(self.w_name)
+            space = self.space
+            name = space.unwrap(self.w_name)
             for sub_name, module_cls in self.submodules.iteritems():
-                module_name = self.space.wrap("%s.%s" % (name, sub_name))
-                m = module_cls(self.space, module_name)
+                module_name = space.wrap("%s.%s" % (name, sub_name))
+                m = module_cls(space, module_name)
                 m.install()
+                space.setitem(self.w_dict, space.wrap(sub_name), space.wrap(m))
 
     def init(self, space):
         """This is called each time the module is imported or reloaded

diff --git a/pypy/interpreter/test/test_mixedmodule.py b/pypy/interpreter/test/test_mixedmodule.py
--- a/pypy/interpreter/test/test_mixedmodule.py
+++ b/pypy/interpreter/test/test_mixedmodule.py
@@ -29,3 +29,29 @@
 
         assert self.space.builtin_modules["test_module"] is m
         assert isinstance(self.space.builtin_modules["test_module.sub"], SubModule)
+
+class AppTestMixedModule(object):
+    def setup_class(cls):
+        space = cls.space
+
+        class SubModule(MixedModule):
+            interpleveldefs = {}
+            appleveldefs = {}
+
+        class Module(MixedModule):
+            interpleveldefs = {}
+            appleveldefs = {}
+            submodules = {
+                "sub": SubModule
+            }
+
+        m = Module(space, space.wrap("test_module"))
+        m.install()
+
+    def test_attibute(self):
+        import test_module
+
+        assert hasattr(test_module, "sub")
+
+    def test_submodule_import(self):
+        from test_module import sub


More information about the Pypy-commit mailing list