From 0def8d712ffc196aeade39744e05209490a858bb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 18 Jun 2020 00:02:39 +0200 Subject: [PATCH 1/2] bpo-41006: Remove init_sys_streams() hack The encodings.latin_1 module is no longer imported at startup. Now it is only imported when it is the filesystem encoding. --- .../2020-06-18-00-07-09.bpo-41006.H-wN-d.rst | 2 ++ Python/pylifecycle.c | 13 ------------- 2 files changed, 2 insertions(+), 13 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst 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 00000000000000..042698979b0d0a --- /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. diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index c754f2169dece0..87f25e623f570d 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; } From b51a5a919fb43252ae369e1b665b4233cae4ee64 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 18 Jun 2020 00:32:19 +0200 Subject: [PATCH 2/2] Update NEWS entry --- .../Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 042698979b0d0a..4593e6bb89a9e9 100644 --- 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 @@ -1,2 +1,2 @@ The ``encodings.latin_1`` module is no longer imported at startup. Now it is -only imported when it is the filesystem encoding. +only imported when it is the filesystem encoding or the stdio encoding.