From: Christian Heimes Date: Fri, 11 Jan 2008 07:03:05 +0000 (+0000) Subject: Good catch Neal! X-Git-Tag: v3.0a3~209 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3540b508844353add804a1ed48e0a73469c385ca;p=thirdparty%2FPython%2Fcpython.git Good catch Neal! I completely forgot about pyo files and the tests are usually not run with -O. The modified code checks for *.py? --- diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index d8f2d51b206b..6eac67e9900e 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -213,7 +213,8 @@ class ImportTest(unittest.TestCase): os.remove(source) del sys.modules[TESTFN] mod = __import__(TESTFN) - self.failUnless(mod.__file__.endswith('.pyc')) + ext = mod.__file__[-4:] + self.failUnless(ext in ('.pyc', '.pyo'), ext) finally: sys.path.pop(0) remove_files(TESTFN) diff --git a/Python/import.c b/Python/import.c index f9d4246a2bdd..cce854fc7c2a 100644 --- a/Python/import.c +++ b/Python/import.c @@ -982,7 +982,8 @@ get_sourcefile(const char *file) } len = strlen(file); - if (len > MAXPATHLEN || PyOS_stricmp(&file[len-4], ".pyc") != 0) { + /* match '*.py?' */ + if (len > MAXPATHLEN || PyOS_strnicmp(&file[len-4], ".py", 3) != 0) { return PyUnicode_DecodeFSDefault(file); }