classification
Title: Confusing error message when giving invalid quotechar in initializing csv dialect
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, serhiy.storchaka, vajrasky
Priority: normal Keywords: patch

Created on 2013-12-20 04:38 by vajrasky, last changed 2013-12-20 07:44 by vajrasky.

Files
File name Uploaded Description Edit
fix_handling_invalid_quotechar.patch vajrasky, 2013-12-20 07:44 For Python 3.3 and 3.4 review
fix_handling_invalid_quotechar_python27.patch vajrasky, 2013-12-20 07:44 For Python 2.7 review
Messages (3)
msg206663 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-20 04:38
Python 3.4.0b1 (default:13a505260f17, Dec 20 2013, 12:02:44) 
[GCC 4.7.2] on linux
>>> import _csv
>>> import csv
>>> _csv.Dialect(quotechar=b'+')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: "quotechar" must be string, not bytes

Hey, that's not true. Quotechar can be None.

>>> _csv.Dialect(quotechar=None)
<_csv.Dialect object at 0x7f64a8534790>

>>> _csv.Dialect(quotechar="cutecat")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: "quotechar" must be an 1-character string

That's not strictly true. Quotechar can be 0-character string in certain situation.

>>> _csv.Dialect(quotechar="", quoting=csv.QUOTE_NONE)
<_csv.Dialect object at 0x7f64a85345f0>

Python 2.7 suffers the same issue.
msg206667 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-20 07:29
Here is the preliminary patch for Python 3.3 and 3.4.
msg206668 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-20 07:36
Here is the preliminary patch for Python 2.7.
History
Date User Action Args
2013-12-20 07:44:25vajraskysetfiles: + fix_handling_invalid_quotechar_python27.patch
2013-12-20 07:44:13vajraskysetfiles: - fix_handling_invalid_quotechar_python27.patch
2013-12-20 07:44:05vajraskysetfiles: + fix_handling_invalid_quotechar.patch
2013-12-20 07:43:48vajraskysetfiles: - fix_handling_invalid_quotechar.patch
2013-12-20 07:36:27vajraskysetfiles: + fix_handling_invalid_quotechar_python27.patch

messages: + msg206668
2013-12-20 07:29:15vajraskysetfiles: + fix_handling_invalid_quotechar.patch
keywords: + patch
messages: + msg206667
2013-12-20 04:38:14vajraskycreate