https://github.com/python/cpython/commit/2c2d8018a20da33c749f42cc6a4ae55664a88321
commit: 2c2d8018a20da33c749f42cc6a4ae55664a88321
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-11-13T20:04:20+03:00
summary:

gh-142662: Fix interpreter startup crash when `codecs` are not initialized yet 
(#161860)

files:
M Python/codecs.c

diff --git a/Python/codecs.c b/Python/codecs.c
index ba6f618f77e6f6..6eb728e7f9f202 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -139,7 +139,10 @@ PyObject *_PyCodec_Lookup(const char *encoding)
     }
 
     PyInterpreterState *interp = _PyInterpreterState_GET();
-    assert(interp->codecs.initialized);
+    if (!interp->codecs.initialized) {
+        PyErr_SetString(PyExc_SystemError, "Codecs are not initialized");
+        return NULL;
+    }
 
     /* Convert the encoding to a normalized Python string: all
        ASCII letters are converted to lower case, spaces are

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to