summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-01-01 17:42:23 (GMT)
committerGitHub <noreply@github.com>2021-01-01 17:42:23 (GMT)
commit6dffa67b98f78ae41b596f84478f3379f55d4d03 (patch)
tree35e822af7c9263229f2071bb24bda6e3a6d62876 /Modules
parentb863607d303a87e8680149361ac987328b35ca5f (diff)
downloadcpython-6dffa67b98f78ae41b596f84478f3379f55d4d03.zip
cpython-6dffa67b98f78ae41b596f84478f3379f55d4d03.tar.gz
cpython-6dffa67b98f78ae41b596f84478f3379f55d4d03.tar.bz2
[3.8] bpo-26407: Do not mask errors in csv. (GH-20536) (GH-24021)
Unexpected errors in calling the __iter__ method are no longer masked by TypeError in csv.reader(), csv.writer.writerow() and csv.writer.writerows(). (cherry picked from commit c88239f864a27f673c0f0a9e62d2488563f9d081)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_csv.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 46d4143..069ec96 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -958,8 +958,6 @@ csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args)
}
self->input_iter = PyObject_GetIter(iterator);
if (self->input_iter == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "argument 1 must be an iterator");
Py_DECREF(self);
return NULL;
}
@@ -1165,10 +1163,14 @@ csv_writerow(WriterObj *self, PyObject *seq)
PyObject *iter, *field, *line, *result;
iter = PyObject_GetIter(seq);
- if (iter == NULL)
- return PyErr_Format(_csvstate_global->error_obj,
- "iterable expected, not %.200s",
- seq->ob_type->tp_name);
+ if (iter == NULL) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError)) {
+ PyErr_Format(_csvstate_global->error_obj,
+ "iterable expected, not %.200s",
+ Py_TYPE(seq)->tp_name);
+ }
+ return NULL;
+ }
/* Join all fields in internal buffer.
*/
@@ -1258,8 +1260,6 @@ csv_writerows(WriterObj *self, PyObject *seqseq)
row_iter = PyObject_GetIter(seqseq);
if (row_iter == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "writerows() argument must be iterable");
return NULL;
}
while ((row_obj = PyIter_Next(row_iter))) {