Skip to content

csv.Sniffer.has_header() leaks ValueError instead of csv.Error for an inconsistent guessed dialect #153634

Description

@tonghuaroot

Bug description:

csv.Sniffer.sniff() can guess a dialect whose delimiter equals its quote character. Using such a dialect leaks a raw ValueError from the _csv extension instead of the module's csv.Error; csv.Sniffer.has_header(), which builds a reader from the sniffed dialect, is the common trigger.

import csv
csv.Sniffer().has_header("''")   # ValueError, not csv.Error

CPython versions tested on:

3.13, 3.14, 3.15

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions