Skip to content

Commit 176050d

Browse files
Raise TypeError if formatter returns a non-string
1 parent 1434a68 commit 176050d

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/test/test_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def formatter(index, value):
535535
def test_write_formatter_errors(self):
536536
with self.assertRaisesRegex(TypeError, 'must be callable or None'):
537537
csv.writer(StringIO(), formatter='str')
538-
with self.assertRaisesRegex(csv.Error, 'must return a string'):
538+
with self.assertRaisesRegex(TypeError, 'must return a string'):
539539
self._write_test([1], '', formatter=lambda index, value: index)
540540
self._write_error_test(ZeroDivisionError, [1],
541541
formatter=lambda index, value: 1/0)

Modules/_csv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ csv_writerow_lock_held(PyObject *op, PyObject *seq)
14631463
str = PyObject_CallFunction(self->formatter, "nO",
14641464
field_index, field);
14651465
if (str != NULL && !PyUnicode_Check(str)) {
1466-
PyErr_Format(self->error_obj,
1466+
PyErr_Format(PyExc_TypeError,
14671467
"formatter must return a string, not %T", str);
14681468
Py_CLEAR(str);
14691469
}

0 commit comments

Comments
 (0)