[Python-checkins] bpo-33128 Fix duplicated call to importlib._install_external_importers (GH-6273)

Nick Coghlan webhook-mailer at python.org
Tue Apr 24 22:22:35 EDT 2018


https://github.com/python/cpython/commit/0977091dca59709864b14cfc129388f1f0de7bf7
commit: 0977091dca59709864b14cfc129388f1f0de7bf7
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: Nick Coghlan <ncoghlan at gmail.com>
date: 2018-04-25T12:22:28+10:00
summary:

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.

files:
A Misc/NEWS.d/next/Core and Builtins/2018-04-24-22-31-04.bpo-33128.g2yLuf.rst
M Lib/test/test_sys.py
M Python/pylifecycle.c

diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 6933b41353bd..336ae447a8de 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -852,6 +852,9 @@ def check(tracebacklimit, expected):
         check(-1<<1000, [traceback[-1]])
         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
 class SizeofTest(unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-04-24-22-31-04.bpo-33128.g2yLuf.rst b/Misc/NEWS.d/next/Core and Builtins/2018-04-24-22-31-04.bpo-33128.g2yLuf.rst
new file mode 100644
index 000000000000..66b98cdf51cf
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-04-24-22-31-04.bpo-33128.g2yLuf.rst	
@@ -0,0 +1,2 @@
+Fix a bug that causes PathFinder to appear twice on sys.meta_path. Patch by
+Pablo Galindo Salgado.
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index a9b9470c7265..958219b74458 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -325,11 +325,6 @@ initimport(PyInterpreterState *interp, PyObject *sysmod)
 
     /* Install importlib as the implementation of import */
     value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
-    if (value != NULL) {
-        Py_DECREF(value);
-        value = PyObject_CallMethod(importlib,
-                                    "_install_external_importers", "");
-    }
     if (value == NULL) {
         PyErr_Print();
         return _Py_INIT_ERR("importlib install failed");



More information about the Python-checkins mailing list