This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: csv: Confusing error message when giving invalid quotechar in initializing dialect
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, iritkatriel, miss-islington, r.david.murray, serhiy.storchaka, vajrasky
Priority: normal Keywords: easy, patch

Created on 2013-12-20 04:38 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

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
Pull Requests
URL Status Linked Edit
PR 28705 merged corona10, 2021-10-03 12:15
PR 28830 merged miss-islington, 2021-10-09 14:50
PR 28831 merged miss-islington, 2021-10-09 14:50
PR 28832 merged corona10, 2021-10-09 14:54
PR 28833 merged corona10, 2021-10-09 15:34
PR 28834 merged corona10, 2021-10-09 15:36
PR 28835 merged corona10, 2021-10-09 15:37
Messages (11)
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.
msg401605 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-09-10 18:01
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>
msg403534 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-10-09 14:50
New changeset 34bbc87b2ddbaf245fbed6443c3e620f80c6a843 by Dong-hee Na in branch 'main':
bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705)
https://github.com/python/cpython/commit/34bbc87b2ddbaf245fbed6443c3e620f80c6a843
msg403535 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-10-09 15:16
New changeset ec04db74e24a5f5da441bcabbe259157b4938b9b by Dong-hee Na in branch 'main':
bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832)
https://github.com/python/cpython/commit/ec04db74e24a5f5da441bcabbe259157b4938b9b
msg403536 - (view) Author: miss-islington (miss-islington) Date: 2021-10-09 15:31
New changeset 6f3bc5eee6729197747d324c167da12902fb7c27 by Miss Islington (bot) in branch '3.9':
bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705)
https://github.com/python/cpython/commit/6f3bc5eee6729197747d324c167da12902fb7c27
msg403537 - (view) Author: miss-islington (miss-islington) Date: 2021-10-09 15:35
New changeset 8772935765e7a4f04f7f561e37d0c0aee71d8030 by Miss Islington (bot) in branch '3.10':
bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705)
https://github.com/python/cpython/commit/8772935765e7a4f04f7f561e37d0c0aee71d8030
msg403539 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-10-09 16:13
New changeset c80f0b7aa1d90332d0069d3e85ee112d0c9da7f0 by Dong-hee Na in branch '3.10':
[3.10] bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832) (GH-28834)
https://github.com/python/cpython/commit/c80f0b7aa1d90332d0069d3e85ee112d0c9da7f0
msg403540 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-10-09 16:13
New changeset e4fcb6fd3dcc4db23867c2fbd538189b8f221225 by Dong-hee Na in branch '3.9':
[3.9] bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832) (GH-28835)
https://github.com/python/cpython/commit/e4fcb6fd3dcc4db23867c2fbd538189b8f221225
msg403651 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-10-11 11:08
New changeset ab62051152cb24470056ffaeb9107c8b4311375e by Dong-hee Na in branch 'main':
bpo-20028: Empty escapechar/quotechar is not allowed for csv.Dialect (GH-28833)
https://github.com/python/cpython/commit/ab62051152cb24470056ffaeb9107c8b4311375e
History
Date User Action Args
2022-04-11 14:57:55adminsetgithub: 64227
2021-10-11 11:09:03corona10setstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-10-11 11:08:19corona10setmessages: + msg403651
2021-10-09 16:13:48corona10setmessages: + msg403540
2021-10-09 16:13:24corona10setmessages: + msg403539
2021-10-09 15:37:07corona10setpull_requests: + pull_request27151
2021-10-09 15:36:30corona10setpull_requests: + pull_request27150
2021-10-09 15:35:36miss-islingtonsetmessages: + msg403537
2021-10-09 15:34:02corona10setpull_requests: + pull_request27149
2021-10-09 15:31:02miss-islingtonsetmessages: + msg403536
2021-10-09 15:16:19corona10setmessages: + msg403535
2021-10-09 14:54:55corona10setpull_requests: + pull_request27148
2021-10-09 14:50:25miss-islingtonsetpull_requests: + pull_request27147
2021-10-09 14:50:21miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request27146
2021-10-09 14:50:20corona10setmessages: + msg403534
2021-10-03 12:15:56corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request27058
2021-10-03 11:49:38corona10setnosy: + corona10
2021-09-10 18:01:26iritkatrielsetnosy: + iritkatriel
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.3, Python 3.4
messages: + msg401605

keywords: + easy, - patch
title: Confusing error message when giving invalid quotechar in initializing csv dialect -> csv: Confusing error message when giving invalid quotechar in initializing dialect
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