[Python-checkins] bpo-41006: Remove init_sys_streams() hack (GH-20954)

Victor Stinner webhook-mailer at python.org
Wed Jun 17 19:11:55 EDT 2020


https://github.com/python/cpython/commit/1bf7959dce0597e312c6f35476a7cc957fd0323c
commit: 1bf7959dce0597e312c6f35476a7cc957fd0323c
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-06-18T01:11:46+02:00
summary:

bpo-41006: Remove init_sys_streams() hack (GH-20954)

The encodings.latin_1 module is no longer imported at startup. Now it
is only imported when it is the filesystem encoding or the stdio encoding.

files:
A Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst
M Python/pylifecycle.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst
new file mode 100644
index 0000000000000..4593e6bb89a9e
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst	
@@ -0,0 +1,2 @@
+The ``encodings.latin_1`` module is no longer imported at startup. Now it is
+only imported when it is the filesystem encoding or the stdio encoding.
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index c754f2169dece..87f25e623f570 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1939,7 +1939,6 @@ static PyStatus
 init_sys_streams(PyThreadState *tstate)
 {
     PyObject *iomod = NULL;
-    PyObject *m;
     PyObject *std = NULL;
     int fd;
     PyObject * encoding_attr;
@@ -1959,18 +1958,6 @@ init_sys_streams(PyThreadState *tstate)
     }
 #endif
 
-    /* Hack to avoid a nasty recursion issue when Python is invoked
-       in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
-    if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) {
-        goto error;
-    }
-    Py_DECREF(m);
-
-    if (!(m = PyImport_ImportModule("encodings.latin_1"))) {
-        goto error;
-    }
-    Py_DECREF(m);
-
     if (!(iomod = PyImport_ImportModule("io"))) {
         goto error;
     }



More information about the Python-checkins mailing list