gh-75008: Detect the lineterminator in csv.Sniffer.sniff() - #155061
Merged
serhiy-storchaka merged 1 commit intoAug 13, 2026
Conversation
It is guessed by a majority vote among the line endings of the sample, instead of always being '\r\n'.
Documentation build overview
|
serhiy-storchaka
enabled auto-merge (squash)
August 13, 2026 10:08
mbeijen
pushed a commit
to mbeijen/cpython
that referenced
this pull request
Aug 14, 2026
…honGH-155061) It is guessed by a majority vote among the line endings of the sample, instead of always being '\r\n'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
csv.Sniffer.sniff()always returnedlineterminator='\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: thereaderrecognizes'\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.