summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-08-26 17:29:40 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-08-26 17:29:40 (GMT)
commit9bcbc6cba385a83cac8f1ff430cad7617184d2bc (patch)
tree93788d8c91a855ce70ac39d466cd2dc9e8633918 /Modules/_io
parent8e67981fc8e1bf3cb9774b5fbf4a39b8d65ba4ff (diff)
downloadcpython-9bcbc6cba385a83cac8f1ff430cad7617184d2bc.zip
cpython-9bcbc6cba385a83cac8f1ff430cad7617184d2bc.tar.gz
cpython-9bcbc6cba385a83cac8f1ff430cad7617184d2bc.tar.bz2
[3.6] bpo-31271: Fix an assertion failure in io.TextIOWrapper.write. (GH-3201) (#3209)
(cherry picked from commit a5b4ea15b61e3f3985f4f0748a18f8b888a63532)
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/textio.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 61adcf6..801bb17 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1331,6 +1331,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);