Skip to content

gh-80678: Document the preferred delimiters of csv.Sniffer#154336

Merged
ambv merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-80678-document-preferred-delimiters
Jul 22, 2026
Merged

gh-80678: Document the preferred delimiters of csv.Sniffer#154336
ambv merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-80678-document-preferred-delimiters

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 21, 2026

Copy link
Copy Markdown
Member

The list of preferred delimiters exists since the module was added in 2003 and has never been documented, so it is only discoverable by reading the source. It decides the result whenever several candidates fit the sample equally well, no matter how many times each of them occurs — the case reported in the issue, a;b;c;d,e;f;g;h, is still detected as ,.

Document this in the Sniffer.sniff() documentation and docstring. The preferred attribute itself stays undocumented.

The delimiters which win when several combinations fit the sample
equally well were not documented.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33683469 | 📁 Comparing 9afd3ca against main (202c4c8)

  🔍 Preview build  

1 file changed
± library/csv.html

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

@smontanaro, you added this list of preferred delimiters in 2003, and you wrote in gh-75008 that you keep half an eye on the csv module. Could you please check that this describes the intended behavior? No obligation of course.

@smontanaro

Copy link
Copy Markdown
Contributor

@smontanaro, you added this list of preferred delimiters in 2003....

I'm going to disclaim any involvement in this. It seems commit 04ae705 was the initial commit for csv.py. I was shepherding the general CSV module development, but wasn't involved with the Sniffer class. I would be more than happy if csv.Sniffer simply disappeared. I've never needed it. I can't imagine there are too many applications where the person manipulating even a large group of CSV files didn't know their basic properties. I have always believed the Sniffer class was a solution in search of a problem. Someone else wrote it, and it landed with everything else.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

I understand you very well. But it seems that it is really used. It is used in Panda, there are also several third-party implementations. Half of csv issues are related to Sniffer (my rewrite in main fixes almost all of them).

@smontanaro

Copy link
Copy Markdown
Contributor

@serhiy-storchaka It looks good to me. Is there a reason for not documenting the preferred attribute and noting that the described sequence of possible delimiters is its initial value?

@ambv
ambv merged commit 79cdcee into python:main Jul 22, 2026
65 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Jul 22, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka and @ambv, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 79cdcee308c6612edd6d1ca972342e2a088b6b4e 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka and @ambv, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 79cdcee308c6612edd6d1ca972342e2a088b6b4e 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka and @ambv, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 79cdcee308c6612edd6d1ca972342e2a088b6b4e 3.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants