Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3540b50

Browse files
committed
Good catch Neal!
I completely forgot about pyo files and the tests are usually not run with -O. The modified code checks for *.py?
1 parent 61ecb77 commit 3540b50

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/test/test_import.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def test_file_to_source(self):
213213
os.remove(source)
214214
del sys.modules[TESTFN]
215215
mod = __import__(TESTFN)
216-
self.failUnless(mod.__file__.endswith('.pyc'))
216+
ext = mod.__file__[-4:]
217+
self.failUnless(ext in ('.pyc', '.pyo'), ext)
217218
finally:
218219
sys.path.pop(0)
219220
remove_files(TESTFN)

Python/import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,8 @@ get_sourcefile(const char *file)
982982
}
983983

984984
len = strlen(file);
985-
if (len > MAXPATHLEN || PyOS_stricmp(&file[len-4], ".pyc") != 0) {
985+
/* match '*.py?' */
986+
if (len > MAXPATHLEN || PyOS_strnicmp(&file[len-4], ".py", 3) != 0) {
986987
return PyUnicode_DecodeFSDefault(file);
987988
}
988989

0 commit comments

Comments
 (0)