From 3f7cc33efb58c84ad93d8f2f36490c823c2e777f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 22 Jul 2026 15:20:08 +0300 Subject: [PATCH] [3.14] gh-80678: Document the preferred delimiters of csv.Sniffer (GH-154336) The delimiters which win when several combinations fit the sample equally well were not documented. (cherry picked from commit 79cdcee308c6612edd6d1ca972342e2a088b6b4e) Co-authored-by: Serhiy Storchaka Co-authored-by: Claude Opus 4.8 (1M context) --- Doc/library/csv.rst | 5 +++++ Lib/csv.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 1eb3fe0d4903539..746d70329751a04 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -314,6 +314,11 @@ The :mod:`!csv` module defines the following classes: is given, it is interpreted as a string containing possible valid delimiter characters. + If several combinations fit the sample equally well --- + for example if both ``','`` and ``';'`` split every row consistently --- + the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'`` + are preferred, in this order, + no matter how many times each of them occurs. .. method:: has_header(sample) diff --git a/Lib/csv.py b/Lib/csv.py index 6efa889ed84677e..843c2e387273292 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -243,6 +243,10 @@ def __init__(self): def sniff(self, sample, delimiters=None): """ Returns a dialect (or None) corresponding to the sample + + If several combinations fit the sample equally well, the + delimiters listed in the preferred attribute are preferred, in + that order, no matter how many times each of them occurs. """ quotechar, doublequote, delimiter, skipinitialspace = \