gh-133036: Deprecate codecs.open (#133038)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Inada Naoki 2025-04-30 10:11:09 +09:00 committed by GitHub
parent 732d1b0241
commit 4e294f6feb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 58 additions and 37 deletions

View file

@ -540,11 +540,19 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
Py_DECREF(attr);
if (is_text_codec <= 0) {
Py_DECREF(codec);
if (!is_text_codec)
PyErr_Format(PyExc_LookupError,
"'%.400s' is not a text encoding; "
"use %s to handle arbitrary codecs",
encoding, alternate_command);
if (!is_text_codec) {
if (alternate_command != NULL) {
PyErr_Format(PyExc_LookupError,
"'%.400s' is not a text encoding; "
"use %s to handle arbitrary codecs",
encoding, alternate_command);
}
else {
PyErr_Format(PyExc_LookupError,
"'%.400s' is not a text encoding",
encoding);
}
}
return NULL;
}
}