bpo-31271: Fix an assertion failure in io.TextIOWrapper.write. (#3201)

This commit is contained in:
Oren Milman 2017-08-25 21:14:54 +03:00 committed by Serhiy Storchaka
parent dce6502059
commit a5b4ea15b6
3 changed files with 17 additions and 0 deletions

View file

@ -1387,6 +1387,13 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
Py_DECREF(text);
if (b == NULL)
return NULL;
if (!PyBytes_Check(b)) {
PyErr_Format(PyExc_TypeError,
"encoder should return a bytes object, not '%.200s'",
Py_TYPE(b)->tp_name);
Py_DECREF(b);
return NULL;
}
if (self->pending_bytes == NULL) {
self->pending_bytes = PyList_New(0);