-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
csv: Confusing error message when giving invalid quotechar in initializing dialect #64227
Comments
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. |
Here is the preliminary patch for Python 3.3 and 3.4. |
Here is the preliminary patch for Python 2.7. |
The patch needs to be converted to a GitHub PR. Reproduced on 3.11: >>> 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
>>> _csv.Dialect(quotechar=None)
<_csv.Dialect object at 0x105acfe40>
>>> _csv.Dialect(quotechar="cutecat")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: "quotechar" must be a 1-character string
>>> _csv.Dialect(quotechar="", quoting=csv.QUOTE_NONE)
<_csv.Dialect object at 0x105948c80> |
What was the motivation here for disallowing an empty escapechar? It seems the original report was intending to point out misleading error messages, not a desired change in functionality. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: