diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-06-22 11:21:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-22 11:21:59 +0300 |
commit | c88239f864a27f673c0f0a9e62d2488563f9d081 (patch) | |
tree | b60c7378df76eef6f7924956a4cf5883f11cbdd9 /Modules/_csv.c | |
parent | cafe1b6e9d3594a34aba50e872d4198296ffaadf (diff) | |
download | cpython-git-c88239f864a27f673c0f0a9e62d2488563f9d081.tar.gz |
bpo-26407: Do not mask errors in csv. (GH-20536)
Unexpected errors in calling the __iter__ method are no longer
masked by TypeError in csv.reader(), csv.writer.writerow() and
csv.writer.writerows().
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r-- | Modules/_csv.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c index 2d4247740e..da61db9377 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -956,8 +956,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; } @@ -1163,10 +1161,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", - Py_TYPE(seq)->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. */ @@ -1256,8 +1258,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))) { |