[3.14] gh-80678: Document the preferred delimiters of csv.Sniffer (GH-154336) (#154590)

hugovk <[email protected]> Fri, 31 Jul 2026 05:34:28 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/dff13256dca15e66353bd5d7c1992744f4248199
commit: dff13256dca15e66353bd5d7c1992744f4248199
branch: 3.14
author: Hugo van Kemenade <[email protected]>
committer: hugovk <[email protected]>
date: 2026-07-31T12:34:13+03:00
summary:

[3.14] gh-80678: Document the preferred delimiters of csv.Sniffer (GH-154336) (#154590)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>

files:
M Doc/library/csv.rst
M Lib/csv.py

diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index 1eb3fe0d490353..64065a75917af8 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 delimiters 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 6efa889ed84677..92bb9b55a4d3eb 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 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.
         """
 
         quotechar, doublequote, delimiter, skipinitialspace = \

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]