diff options
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/textio.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 5103ae6..402f743 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -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); |