Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-20028: Improve error message of csv.Dialect when initializing #28705

Merged
merged 7 commits into from Oct 9, 2021

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Oct 3, 2021

https://bugs.python.org/issue20028

@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 3, 2021

./python.exe -m test test_csv -R 3:3
0:00:00 load avg: 2.50 Run tests sequentially
0:00:00 load avg: 2.50 [1/1] test_csv
beginning 6 repetitions
123456
......

== Tests result: SUCCESS ==

1 test OK.

Total duration: 3.6 sec
Tests result: SUCCESS

Modules/_csv.c Show resolved Hide resolved
@corona10 corona10 requested a review from iritkatriel Oct 4, 2021
@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 6, 2021

@smontanaro Can you please take a look?

Modules/_csv.c Outdated
@@ -457,7 +465,7 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto err;
if (self->delimiter == 0) {
PyErr_SetString(PyExc_TypeError,
"\"delimiter\" must be a 1-character string");
"delimiter must be set");
Copy link
Contributor

@smontanaro smontanaro Oct 6, 2021

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.

Copy link
Member Author

@corona10 corona10 Oct 6, 2021

Okay, I agree that the message doesn't need to be changed.

Copy link
Member

@serhiy-storchaka serhiy-storchaka Oct 7, 2021

It was made consistent with error messages for other arguments.

@smontanaro
Copy link
Contributor

@smontanaro smontanaro commented Oct 6, 2021

@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.

@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 7, 2021

@iritkatriel gentle ping :)

@iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Oct 8, 2021

Looks fine, would be nice to add a coauthored-by crediting the original patch author.

@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 9, 2021

@serhiy-storchaka
if we apply #28808, should we drop this PR?
This PR will make an error .

self._read_test(['a,\\b,c'], [['a', '\\b', 'c']], escapechar='')
# TypeError: "escapechar" must be a 1-character string

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Oct 9, 2021

#28808 and this PR are almost unrelyted. I was going to merge #28808 after merging this PR if the purpose of this PR is just improving error messages.

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) {
Copy link
Member

@serhiy-storchaka serhiy-storchaka Oct 9, 2021

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().

@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 9, 2021

@serhiy-storchaka
Thanks for the review.

It may be simpler to introduce different function _set_char_or_none()

I follow your code review, Please take a look.

PR is just improving error messages.

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
self._read_test(['a,\b,c'], [['a', '\b', 'c']], escapechar='') -> not allowed.

Please let me know your intention, I will update the PR to follow your intention :)

Modules/_csv.c Outdated Show resolved Hide resolved
Modules/_csv.c Show resolved Hide resolved
@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Oct 9, 2021

This PR will not allow zero-length string, is this should be allowed?

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 PyUnicode_GetLength() is not handled. Its fix should be backported too.

So you can split this PR on 2 or 3 PRs (better error message, handle error in PyUnicode_GetLength(), disallow empty escapechar/quotechar) and merge and backport them separately. or merge the combined PR and remove some changes in backports.

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.

@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 9, 2021

Okay let's separate the PR into 3 PRs

  • part1 better error message
  • part2 handle error in PyUnicode_GetLength()
  • part3 disallow empty escapechar/quotechar

@corona10 corona10 changed the title bpo-20028: Update csv module to hanlde the giving invalid quotechar. bpo-20028: Improve error message of csv.Dialect when initializing Oct 9, 2021
@corona10 corona10 merged commit 34bbc87 into python:main Oct 9, 2021
12 checks passed
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Oct 9, 2021

Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒🤖

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 9, 2021

GH-28830 is a backport of this pull request to the 3.10 branch.

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 9, 2021

GH-28831 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit to miss-islington/cpython that referenced this issue Oct 9, 2021
…thonGH-28705)

(cherry picked from commit 34bbc87)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
miss-islington added a commit to miss-islington/cpython that referenced this issue Oct 9, 2021
…thonGH-28705)

(cherry picked from commit 34bbc87)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
@corona10 corona10 deleted the bpo-20028 branch Oct 9, 2021
miss-islington added a commit that referenced this issue Oct 9, 2021
…-28705)

(cherry picked from commit 34bbc87)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
miss-islington added a commit that referenced this issue Oct 9, 2021
…-28705)

(cherry picked from commit 34bbc87)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 9, 2021

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Gentoo Installed with X 3.9 has failed when building commit 6f3bc5e.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/527/builds/264) and take a look at the build logs.
  4. Check if the failure is related to this commit (6f3bc5e) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/527/builds/264

Failed tests:

  • test_ttk_guionly
  • test_tk

Failed subtests:

  • test_configure_compound - tkinter.test.test_ttk.test_widgets.LabelTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.CheckbuttonTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.RadiobuttonTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.ButtonTest
  • test_configure_type - tkinter.test.test_tkinter.test_widgets.MenuTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.MenubuttonTest

Summary of the results of the build (if available):

== Tests result: FAILURE then FAILURE ==

410 tests OK.

2 tests failed:
test_tk test_ttk_guionly

13 tests skipped:
test_asdl_parser test_check_c_globals test_clinic test_devpoll
test_gdb test_ioctl test_kqueue test_msilib test_startfile
test_winconsoleio test_winreg test_winsound test_zipfile64

2 re-run tests:
test_tk test_ttk_guionly

Total duration: 39 min

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.installed/build/target/lib/python3.9/tkinter/test/test_tkinter/test_widgets.py", line 1244, in test_configure_type
    self.checkEnumParam(widget, 'type',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.installed/build/target/lib/python3.9/tkinter/test/widget_tests.py", line 151, in checkEnumParam
    self.checkInvalidParam(widget, name, '',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.installed/build/target/lib/python3.9/tkinter/test/widget_tests.py", line 74, in checkInvalidParam
    widget[name] = value
AssertionError: TclError not raised


Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.installed/build/target/lib/python3.9/tkinter/test/test_ttk/test_widgets.py", line 173, in test_configure_compound
    self.checkEnumParam(widget, 'compound',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.installed/build/target/lib/python3.9/tkinter/test/widget_tests.py", line 151, in checkEnumParam
    self.checkInvalidParam(widget, name, '',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.installed/build/target/lib/python3.9/tkinter/test/widget_tests.py", line 74, in checkInvalidParam
    widget[name] = value
AssertionError: TclError not raised

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 9, 2021

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Gentoo Non-Debug with X 3.9 has failed when building commit 6f3bc5e.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/51/builds/265) and take a look at the build logs.
  4. Check if the failure is related to this commit (6f3bc5e) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/51/builds/265

Failed tests:

  • test_ttk_guionly
  • test_tk

Failed subtests:

  • test_configure_compound - tkinter.test.test_ttk.test_widgets.LabelTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.CheckbuttonTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.RadiobuttonTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.ButtonTest
  • test_configure_type - tkinter.test.test_tkinter.test_widgets.MenuTest
  • test_configure_compound - tkinter.test.test_ttk.test_widgets.MenubuttonTest

Summary of the results of the build (if available):

== Tests result: FAILURE then FAILURE ==

414 tests OK.

10 slowest tests:

  • test_peg_generator: 19 min 45 sec
  • test_concurrent_futures: 5 min 27 sec
  • test_unparse: 4 min 55 sec
  • test_tokenize: 4 min 44 sec
  • test_multiprocessing_spawn: 4 min 42 sec
  • test_lib2to3: 3 min 16 sec
  • test_asyncio: 2 min 51 sec
  • test_multiprocessing_forkserver: 2 min 50 sec
  • test_capi: 1 min 39 sec
  • test_multiprocessing_fork: 1 min 39 sec

2 tests failed:
test_tk test_ttk_guionly

9 tests skipped:
test_devpoll test_ioctl test_kqueue test_msilib test_startfile
test_winconsoleio test_winreg test_winsound test_zipfile64

2 re-run tests:
test_tk test_ttk_guionly

Total duration: 49 min 45 sec

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.nondebug/build/Lib/tkinter/test/test_ttk/test_widgets.py", line 173, in test_configure_compound
    self.checkEnumParam(widget, 'compound',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.nondebug/build/Lib/tkinter/test/widget_tests.py", line 151, in checkEnumParam
    self.checkInvalidParam(widget, name, '',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.nondebug/build/Lib/tkinter/test/widget_tests.py", line 74, in checkInvalidParam
    widget[name] = value
AssertionError: TclError not raised


Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.nondebug/build/Lib/tkinter/test/test_tkinter/test_widgets.py", line 1244, in test_configure_type
    self.checkEnumParam(widget, 'type',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.nondebug/build/Lib/tkinter/test/widget_tests.py", line 151, in checkEnumParam
    self.checkInvalidParam(widget, name, '',
  File "/buildbot/buildarea/cpython/3.9.ware-gentoo-x86.nondebug/build/Lib/tkinter/test/widget_tests.py", line 74, in checkInvalidParam
    widget[name] = value
AssertionError: TclError not raised

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants