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

csv: Confusing error message when giving invalid quotechar in initializing dialect #64227

Closed
vajrasky mannequin opened this issue Dec 20, 2013 · 12 comments
Closed

csv: Confusing error message when giving invalid quotechar in initializing dialect #64227

vajrasky mannequin opened this issue Dec 20, 2013 · 12 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Dec 20, 2013

BPO 20028
Nosy @bitdancer, @serhiy-storchaka, @vajrasky, @corona10, @miss-islington, @iritkatriel
PRs
  • bpo-20028: Improve error message of csv.Dialect when initializing #28705
  • [3.10] bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705) #28830
  • [3.9] bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705) #28831
  • bpo-20028: Keep original exception when PyUnicode_GetLength return -1 #28832
  • bpo-20028: Empty escapechar/quotechar is not allowed for csv.Dialect #28833
  • [3.10] bpo-20028: Keep original exception when PyUnicode_GetLength re… #28834
  • [3.9] bpo-20028: Keep original exception when PyUnicode_GetLength ret… #28835
  • Files
  • fix_handling_invalid_quotechar.patch: For Python 3.3 and 3.4
  • fix_handling_invalid_quotechar_python27.patch: For Python 2.7
  • 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:

    assignee = None
    closed_at = <Date 2021-10-11.11:09:03.163>
    created_at = <Date 2013-12-20.04:38:14.524>
    labels = ['easy', 'type-bug', '3.9', '3.10', '3.11', 'library']
    title = 'csv: Confusing error message when giving invalid quotechar in initializing dialect'
    updated_at = <Date 2021-10-11.11:09:03.163>
    user = 'https://github.com/vajrasky'

    bugs.python.org fields:

    activity = <Date 2021-10-11.11:09:03.163>
    actor = 'corona10'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-11.11:09:03.163>
    closer = 'corona10'
    components = ['Library (Lib)']
    creation = <Date 2013-12-20.04:38:14.524>
    creator = 'vajrasky'
    dependencies = []
    files = ['33226', '33227']
    hgrepos = []
    issue_num = 20028
    keywords = ['patch', 'easy']
    message_count = 11.0
    messages = ['206663', '206667', '206668', '401605', '403534', '403535', '403536', '403537', '403539', '403540', '403651']
    nosy_count = 6.0
    nosy_names = ['r.david.murray', 'serhiy.storchaka', 'vajrasky', 'corona10', 'miss-islington', 'iritkatriel']
    pr_nums = ['28705', '28830', '28831', '28832', '28833', '28834', '28835']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20028'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 20, 2013

    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.

    @vajrasky vajrasky mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 20, 2013
    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 20, 2013

    Here is the preliminary patch for Python 3.3 and 3.4.

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 20, 2013

    Here is the preliminary patch for Python 2.7.

    @iritkatriel
    Copy link
    Member

    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>

    @iritkatriel iritkatriel added easy 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Sep 10, 2021
    @iritkatriel iritkatriel changed the title Confusing error message when giving invalid quotechar in initializing csv dialect csv: Confusing error message when giving invalid quotechar in initializing dialect Sep 10, 2021
    @corona10
    Copy link
    Member

    corona10 commented Oct 9, 2021

    New changeset 34bbc87 by Dong-hee Na in branch 'main':
    bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705)
    34bbc87

    @corona10
    Copy link
    Member

    corona10 commented Oct 9, 2021

    New changeset ec04db7 by Dong-hee Na in branch 'main':
    bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832)
    ec04db7

    @miss-islington
    Copy link
    Contributor

    New changeset 6f3bc5e by Miss Islington (bot) in branch '3.9':
    bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705)
    6f3bc5e

    @miss-islington
    Copy link
    Contributor

    New changeset 8772935 by Miss Islington (bot) in branch '3.10':
    bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705)
    8772935

    @corona10
    Copy link
    Member

    corona10 commented Oct 9, 2021

    New changeset c80f0b7 by Dong-hee Na in branch '3.10':
    [3.10] bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832) (GH-28834)
    c80f0b7

    @corona10
    Copy link
    Member

    corona10 commented Oct 9, 2021

    New changeset e4fcb6f by Dong-hee Na in branch '3.9':
    [3.9] bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832) (GH-28835)
    e4fcb6f

    @corona10
    Copy link
    Member

    New changeset ab62051 by Dong-hee Na in branch 'main':
    bpo-20028: Empty escapechar/quotechar is not allowed for csv.Dialect (GH-28833)
    ab62051

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @GPHemsley-RELX
    Copy link

    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.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants