cvs -z3 diff -u dist\src\Lib\test\test_importhooks.py dist\src\Python\import.c (in directory C:\cvs\python\) Index: dist/src/Lib/test/test_importhooks.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_importhooks.py,v retrieving revision 1.2 diff -u -r1.2 test_importhooks.py --- dist/src/Lib/test/test_importhooks.py 17 Feb 2003 14:51:41 -0000 1.2 +++ dist/src/Lib/test/test_importhooks.py 16 Sep 2004 20:40:01 -0000 @@ -157,12 +157,41 @@ "hooktestpackage.sub") self.assertEqual(hooktestpackage.sub.subber.get_name(), "hooktestpackage.sub.subber") + + # Make sure our new method is not there + self.assertEqual(False, hasattr(hooktestmodule, 'get_foo')) + if importer: self.assertEqual(hooktestmodule.__loader__, importer) self.assertEqual(hooktestpackage.__loader__, importer) self.assertEqual(hooktestpackage.sub.__loader__, importer) self.assertEqual(hooktestpackage.sub.subber.__loader__, importer) + # Test reload + new_test_co = compile(test_src + "\ndef get_foo(): return 1", "", "exec") + TestImporter.modules = { + "hooktestmodule": (False, new_test_co), + "hooktestpackage": (True, new_test_co), + "hooktestpackage.sub": (True, new_test_co), + "hooktestpackage.sub.subber": (False, new_test_co), + } + + try: + # Before just 'reload(hooktestmodule)' worked, but now we have to reassign hooktestmodule + hooktestmodule = reload(hooktestmodule) + + # Make sure our new method /is/ there + self.assertEqual(hooktestmodule.get_name(), "hooktestmodule") + self.assertEqual(hooktestmodule.get_foo(), 1) + finally: + # Put the old code back for the next test + TestImporter.modules = { + "hooktestmodule": (False, test_co), + "hooktestpackage": (True, test_co), + "hooktestpackage.sub": (True, test_co), + "hooktestpackage.sub.subber": (False, test_co), + } + def testMetaPath(self): i = MetaImporter() sys.meta_path.append(i) Index: dist/src/Python/import.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/import.c,v retrieving revision 2.237 diff -u -r2.237 import.c --- dist/src/Python/import.c 23 Aug 2004 23:37:48 -0000 2.237 +++ dist/src/Python/import.c 16 Sep 2004 22:30:33 -0000 @@ -2251,7 +2251,7 @@ PyImport_ReloadModule(PyObject *m) { PyObject *modules = PyImport_GetModuleDict(); - PyObject *path = NULL; + PyObject *path = NULL, *loader = NULL; char *name, *subname; char buf[MAXPATHLEN+1]; struct filedescr *fdp; @@ -2294,11 +2294,12 @@ PyErr_Clear(); } buf[0] = '\0'; - fdp = find_module(name, subname, path, buf, MAXPATHLEN+1, &fp, NULL); + fdp = find_module(name, subname, path, buf, MAXPATHLEN+1, &fp, &loader); Py_XDECREF(path); if (fdp == NULL) return NULL; - newm = load_module(name, fp, buf, fdp->type, NULL); + newm = load_module(name, fp, buf, fdp->type, loader); + Py_XDECREF(loader); if (fp) fclose(fp); if (newm == NULL) {