Index: Lib/test/test_importhooks.py =================================================================== --- Lib/test/test_importhooks.py (revision 3134) +++ Lib/test/test_importhooks.py (working copy) @@ -186,7 +186,7 @@ else: self.fail("'%s' was not supposed to be importable" % mname) - def testImpWrapper(self): + def doTestImpWrapper(self, globals_func=globals, locals_func=locals): i = ImpWrapper() sys.meta_path.append(i) sys.path_hooks.append(ImpWrapper) @@ -198,9 +198,15 @@ if n.startswith(parent): del sys.modules[n] for mname in mnames: - m = __import__(mname, globals(), locals(), ["__dummy__"]) + m = __import__(mname, globals_func(), locals_func(), ["__dummy__"]) m.__loader__ # to make sure we actually handled the import + def testImpWrapper(self): + self.doTestImpWrapper() + + def testImpWrapperNoContext(self): + self.doTestImpWrapper(lambda: None, lambda: None) + def test_main(): test_support.run_unittest(ImportHooksTestCase) Index: src/org/python/core/imp.java =================================================================== --- src/org/python/core/imp.java (revision 3134) +++ src/org/python/core/imp.java (working copy) @@ -636,7 +636,7 @@ PyObject modules = Py.getSystemState().modules; PyObject pkgMod = null; String pkgName = null; - if (modDict != null) { + if (modDict != null && !(modDict instanceof PyNone)) { pkgName = getParent(modDict); pkgMod = modules.__finditem__(pkgName); // System.err.println("GetParent: " + pkgName + " => " + pkgMod);