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

Skip to content

Commit 8923a4d

Browse files
committed
Issue #14605: Insert to the front of sys.path_hooks instead of appending.
1 parent 4fe29c9 commit 8923a4d

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

Lib/test/test_importhooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def testMetaPath(self):
215215
self.doTestImports(i)
216216

217217
def testPathHook(self):
218-
sys.path_hooks.append(PathImporter)
218+
sys.path_hooks.insert(0, PathImporter)
219219
sys.path.append(test_path)
220220
self.doTestImports()
221221

@@ -228,7 +228,7 @@ def testBlocker(self):
228228
def testImpWrapper(self):
229229
i = ImpWrapper()
230230
sys.meta_path.append(i)
231-
sys.path_hooks.append(ImpWrapper)
231+
sys.path_hooks.insert(0, ImpWrapper)
232232
mnames = (
233233
"colorsys", "urllib.parse", "distutils.core", "sys",
234234
)

Lib/test/test_threaded_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_parallel_path_hooks(self):
145145
def path_hook(path):
146146
finder.find_module('')
147147
raise ImportError
148-
sys.path_hooks.append(path_hook)
148+
sys.path_hooks.insert(0, path_hook)
149149
sys.meta_path.append(flushing_finder)
150150
try:
151151
# Flush the cache a first time

Python/import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ _PyImportZip_Init(void)
268268
"# can't import zipimport.zipimporter\n");
269269
}
270270
else {
271-
/* sys.path_hooks.append(zipimporter) */
272-
err = PyList_Append(path_hooks, zipimporter);
271+
/* sys.path_hooks.insert(0, zipimporter) */
272+
err = PyList_Insert(path_hooks, 0, zipimporter);
273273
Py_DECREF(zipimporter);
274274
if (err < 0) {
275275
goto error;

0 commit comments

Comments
 (0)