GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-75008: Detect the lineterminator in csv.Sniffer.sniff() by serhiy-storchaka · Pull Request #155061 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 1, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

csv.Sniffer.sniff() always returned lineterminator='\r\n'. It is now guessed by a majority vote among the line endings of the sample, which the line splitter already preserves. A tie is broken in the order '\r\n', '\n', '\r', so a sample without a complete line still gives '\r\n'.

A line break inside a quoted field is counted too, because the vote is taken over the raw lines of the sample. It only wins if such breaks outnumber the real ones. Excluding them is possible on top of this (record which lines the reader pulls for each row), but it is not needed for the majority vote.

This only affects the writer: the reader recognizes '\r' and '\n' as end-of-line and ignores lineterminator.

PR #18336 addresses the same issue against the old sniffer, which was replaced by trial parsing in gh-83273.

  • Issue: csv.Sniffer does not detect lineterminator #75008

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
pythongh-75008: Detect the lineterminator in csv.Sniffer.sniff()
9d1a329
It is guessed by a majority vote among the line endings of the sample,
instead of always being '\r\n'.
@serhiy-storchaka
serhiy-storchaka requested a review from AA-Turner as a code owner August 1, 2026 21:03
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 1, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Aug 1, 2026
csv.Sniffer does not detect lineterminator #75008
Closed
@read-the-docs-community

read-the-docs-community Bot commented Aug 1, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33870308 | 📁 Comparing 9d1a329 against main (7b4165b)

  🔍 Preview build  

3 files changed
± library/csv.html
± whatsnew/3.16.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka serhiy-storchaka mentioned this pull request Aug 1, 2026
gh-75008: guess lineterminator in csv.Sniffer #18336
Closed
@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) August 13, 2026 10:08
@serhiy-storchaka
serhiy-storchaka merged commit 3157786 into python:main Aug 13, 2026
98 of 100 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Aug 13, 2026
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
@serhiy-storchaka @mbeijen
pythongh-75008: Detect the lineterminator in csv.Sniffer.sniff() (pyt…
e13d86d
…honGH-155061)

It is guessed by a majority vote among the line endings of the sample,
instead of always being '\r\n'.
@serhiy-storchaka
serhiy-storchaka deleted the csv-sniffer-lineterminator branch August 27, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@serhiy-storchaka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.