bpo-20028: Improve error message of csv.Dialect when initializing#28705
bpo-20028: Improve error message of csv.Dialect when initializing#28705corona10 merged 7 commits intopython:mainfrom
Conversation
|
|
@smontanaro Can you please take a look? |
Modules/_csv.c
Outdated
There was a problem hiding this comment.
I think "set" might confuse naive readers. What was wrong with the previous spelling? Also, note that "delimiter" was quoted because it was explicitly referring to the "dellimiter" attribute.
There was a problem hiding this comment.
Okay, I agree that the message doesn't need to be changed.
There was a problem hiding this comment.
It was made consistent with error messages for other arguments.
|
@iritkatriel While the new test ("!=" vs ">") is technically more correct and might be worthwhile in 3.11, I don't think that change can be backported, since it might break existing code. |
|
@iritkatriel gentle ping :) |
|
Looks fine, would be nice to add a coauthored-by crediting the original patch author. |
|
@serhiy-storchaka self._read_test(['a,\\b,c'], [['a', '\\b', 'c']], escapechar='')
# TypeError: "escapechar" must be a 1-character string |
Modules/_csv.c
Outdated
| PyErr_Format(PyExc_TypeError, | ||
| "\"%s\" must be string, not %.200s", name, | ||
| Py_TYPE(src)->tp_name); | ||
| if (strcmp(name, "delimiter") == 0) { |
There was a problem hiding this comment.
If we tweak this error message, we should also raise the same error if delimiter=None.
It may be simpler to introduce different function _set_char_or_none().
|
@serhiy-storchaka
I follow your code review, Please take a look.
This PR will not allow zero-length string, is this should be allowed? self._read_test(['a,\0b,c'], [['a', 'b', 'c']], escapechar='\0') -> allowed Please let me know your intention, I will update the PR to follow your intention :) |
This is undocumented behavior, and I believe it is not intentional. I think that the change for more correct error message could be backported to 3.9 and 3.10, but the change in handling empty strings should be only in 3.11. Also there is a bug, error in So you can split this PR on 2 or 3 PRs (better error message, handle error in Ah, and it would be nice to disallow empty lineterminator, and disallow conflicts (e.g. the same char for delimiter, escapechar or quotechar), but this is a different issue. |
|
Okay let's separate the PR into 3 PRs
|
|
Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
|
GH-28830 is a backport of this pull request to the 3.10 branch. |
|
GH-28831 is a backport of this pull request to the 3.9 branch. |
…thonGH-28705) (cherry picked from commit 34bbc87) Co-authored-by: Dong-hee Na <donghee.na@python.org>
…thonGH-28705) (cherry picked from commit 34bbc87) Co-authored-by: Dong-hee Na <donghee.na@python.org>
|
|
Please see bpo 20028. python/cpython#28705. This shows up in nightlies, but I have no way to test this. It should show up pretty soon in regular CI. Can someone with with the perms on the MacPython repo please trigger the nightlies manually to see if that fixes the builds? Thanks.
https://bugs.python.org/issue20028