Skip to content

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

Closed

Description

@vajrasky
mannequin
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']

    Activity

    1. vajrasky commented on Dec 20, 2013

      vajraskymannequin
      MannequinAuthor
      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Dec 20, 2013
    3. vajrasky commented on Dec 20, 2013

      vajraskymannequin
      MannequinAuthor

      Here is the preliminary patch for Python 3.3 and 3.4.

    4. vajrasky commented on Dec 20, 2013

      vajraskymannequin
      MannequinAuthor

      Here is the preliminary patch for Python 2.7.

    5. iritkatriel commented on Sep 10, 2021

      @iritkatriel
      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>
    6. 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[/+] on Sep 10, 2021
    7. corona10 commented on Oct 9, 2021

      @corona10
      Member

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

    8. corona10 commented on Oct 9, 2021

      @corona10
      Member

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

    9. miss-islington commented on Oct 9, 2021

      @miss-islington
      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

    10. miss-islington commented on Oct 9, 2021

      @miss-islington
      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

    11. corona10 commented on Oct 9, 2021

      @corona10
      Member

      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

    12. corona10 commented on Oct 9, 2021

      @corona10
      Member

      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

    13. corona10 commented on Oct 11, 2021

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

    14. transferred this issue fromon Apr 10, 2022
    15. GPHemsley-RELX commented on Dec 19, 2023

      @GPHemsley-RELX

      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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifeeasystdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions