From 5c4ba451d25143fad9ef8a9278c48ca9237444ac Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 22 Jul 2026 15:20:08 +0300 Subject: [PATCH 1/2] [3.13] 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 8f105eeac77bbc2..a202cebad885331 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 b73ad049d981665..46455b5f8d36bb0 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -244,6 +244,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 = \ From 8302fb7244c7d2894abb47940fd899e9db4ea49b Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 26 Jul 2026 21:40:21 +0300 Subject: [PATCH 2/2] Say 'delimiters', not 'combinations' The maintenance branches do not deduce the dialect by trying combinations of parameters, so only the delimiter candidates can tie. --- Doc/library/csv.rst | 2 +- Lib/csv.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index a202cebad885331..ee1ea87d68655f5 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -314,7 +314,7 @@ 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 --- + If several delimiters fit the sample equally well --- for example if both ``','`` and ``';'`` split every row consistently --- the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'`` are preferred, in this order, diff --git a/Lib/csv.py b/Lib/csv.py index 46455b5f8d36bb0..905e5b6ac077d3f 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -245,7 +245,7 @@ def sniff(self, sample, delimiters=None): """ Returns a dialect (or None) corresponding to the sample - If several combinations fit the sample equally well, the + If several delimiters 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. """