Skip to content

Commit 5680bff

Browse files
committed
bpo-20028: Seperate the PR
1 parent a9fd17b commit 5680bff

3 files changed

Lines changed: 4 additions & 20 deletions

File tree

Lib/test/test_csv.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -899,12 +899,6 @@ class mydialect(csv.Dialect):
899899
self.assertEqual(str(cm.exception),
900900
'"quotechar" must be string or None, not int')
901901

902-
mydialect.quotechar = ""
903-
with self.assertRaises(csv.Error) as cm:
904-
mydialect()
905-
self.assertEqual(str(cm.exception),
906-
'"quotechar" must be a 1-character string')
907-
908902
def test_delimiter(self):
909903
class mydialect(csv.Dialect):
910904
delimiter = ";"
@@ -957,10 +951,6 @@ class mydialect(csv.Dialect):
957951
d = mydialect()
958952
self.assertEqual(d.escapechar, "\\")
959953

960-
mydialect.escapechar = ""
961-
with self.assertRaisesRegex(csv.Error, '"escapechar" must be a 1-character string'):
962-
mydialect()
963-
964954
mydialect.escapechar = "**"
965955
with self.assertRaisesRegex(csv.Error, '"escapechar" must be a 1-character string'):
966956
mydialect()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Update :mod:`csv` to handle the giving invalid quotechar correctly for
2-
initializing *dialect*. Patch by Vajrasky Kok and Dong-hee Na.
1+
Improve error message of :class:`csv.Dialect` when initializing.
2+
Patch by Vajrasky Kok and Dong-hee Na.

Modules/_csv.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,7 @@ _set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt
244244
return -1;
245245
}
246246
Py_ssize_t len = PyUnicode_GetLength(src);
247-
if (len < 0) {
248-
return -1;
249-
}
250-
if (len != 1) {
247+
if (len > 1) {
251248
PyErr_Format(PyExc_TypeError,
252249
"\"%s\" must be a 1-character string",
253250
name);
@@ -277,10 +274,7 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
277274
return -1;
278275
}
279276
Py_ssize_t len = PyUnicode_GetLength(src);
280-
if (len < 0) {
281-
return -1;
282-
}
283-
if (len != 1) {
277+
if (len > 1) {
284278
PyErr_Format(PyExc_TypeError,
285279
"\"%s\" must be a 1-character string",
286280
name);

0 commit comments

Comments
 (0)