Skip to content

Commit 52a5a17

Browse files
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 0977091) Co-authored-by: Pablo Galindo <[email protected]>
1 parent 75a3e3d commit 52a5a17

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Lib/test/test_sys.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,9 @@ def check(tracebacklimit, expected):
852852
check(-1<<1000, [traceback[-1]])
853853
check(None, traceback)
854854

855+
def test_no_duplicates_in_meta_path(self):
856+
self.assertEqual(len(sys.meta_path), len(set(sys.meta_path)))
857+
855858

856859
@test.support.cpython_only
857860
class SizeofTest(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug that causes PathFinder to appear twice on sys.meta_path. Patch by
2+
Pablo Galindo Salgado.

Python/pylifecycle.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,6 @@ initimport(PyInterpreterState *interp, PyObject *sysmod)
325325

326326
/* Install importlib as the implementation of import */
327327
value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
328-
if (value != NULL) {
329-
Py_DECREF(value);
330-
value = PyObject_CallMethod(importlib,
331-
"_install_external_importers", "");
332-
}
333328
if (value == NULL) {
334329
PyErr_Print();
335330
return _Py_INIT_ERR("importlib install failed");

0 commit comments

Comments
 (0)