diff options
Diffstat (limited to 'Objects/unicodeobject.c')
| -rw-r--r-- | Objects/unicodeobject.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 26d6fc64ee..d4a17ce43b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -5634,6 +5634,12 @@ unicode_encode(PyUnicodeObject *self, PyObject *args) if (v == NULL) goto onError; if (!PyBytes_Check(v)) { + if (PyString_Check(v)) { + /* Old codec, turn it into bytes */ + PyObject *b = PyBytes_FromObject(v); + Py_DECREF(v); + return b; + } PyErr_Format(PyExc_TypeError, "encoder did not return a bytes object " "(type=%.400s)", |
