bpo-33128 Fix duplicated call to importlib._install_external_importers (GH-6273)

External importers were being added in both phases of the import
system initialisation.

They're only supposed to be added in the second phase, after the
import machinery has been appropriately configured.
(cherry picked from commit 0977091dca)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-04-24 19:48:04 -07:00 committed by GitHub
parent 75a3e3d5bc
commit 52a5a17338
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View file

@ -852,6 +852,9 @@ class SysModuleTest(unittest.TestCase):
check(-1<<1000, [traceback[-1]]) check(-1<<1000, [traceback[-1]])
check(None, traceback) check(None, traceback)
def test_no_duplicates_in_meta_path(self):
self.assertEqual(len(sys.meta_path), len(set(sys.meta_path)))
@test.support.cpython_only @test.support.cpython_only
class SizeofTest(unittest.TestCase): class SizeofTest(unittest.TestCase):

View file

@ -0,0 +1,2 @@
Fix a bug that causes PathFinder to appear twice on sys.meta_path. Patch by
Pablo Galindo Salgado.

View file

@ -325,11 +325,6 @@ initimport(PyInterpreterState *interp, PyObject *sysmod)
/* Install importlib as the implementation of import */ /* Install importlib as the implementation of import */
value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod); value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
if (value != NULL) {
Py_DECREF(value);
value = PyObject_CallMethod(importlib,
"_install_external_importers", "");
}
if (value == NULL) { if (value == NULL) {
PyErr_Print(); PyErr_Print();
return _Py_INIT_ERR("importlib install failed"); return _Py_INIT_ERR("importlib install failed");