Skip to content

gh-103925: csv.py _guess_quote_and_delimiter should be able to handle windows \r#103926

Merged
serhiy-storchaka merged 8 commits into
python:mainfrom
lilaboc:fix-issue-103925
Jul 21, 2026
Merged

gh-103925: csv.py _guess_quote_and_delimiter should be able to handle windows \r#103926
serhiy-storchaka merged 8 commits into
python:mainfrom
lilaboc:fix-issue-103925

Conversation

@lilaboc

@lilaboc lilaboc commented Apr 27, 2023

Copy link
Copy Markdown
Contributor

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost

ghost commented Apr 27, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

Comment thread Lib/csv.py Outdated
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the space rule here is to "align the comments but make the lines as short as possible", which basically means align to the longest line. Now with your change, the third line becomes the longest, so you should probably leave one space between the comment and the code on the third line, and align with that. (one extra space on the other lines if I counted correctly)

@lilaboc lilaboc Apr 27, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8: E261 at least two spaces before inline comment
I made another commit to use 2 spaces for now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, two definitely works. The original code uses a single space, probably because the line was long. But two is good for me.

Comment thread Lib/test/test_csv.py Outdated
Comment thread Misc/NEWS.d/next/Library/2023-04-27-14-50-03.gh-issue-103925.khC-El.rst Outdated
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 12, 2026
serhiy-storchaka and others added 2 commits July 21, 2026 07:46
Conflict in Lib/test/test_csv.py: sample15 was taken by another test
in the meantime.  Rename the sample added here to sample19 and keep
the assertions of both sides.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Describe the user visible effect instead of the implementation, and do
not reference a private function which cannot be linked.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@@ -0,0 +1 @@
support "\\r" in :func:`_guess_quote_and_delimiter`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NEWS entry should talk about user visible API and behavior, not about private functions.

@serhiy-storchaka serhiy-storchaka added 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 labels Jul 21, 2026

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the branch, resolved conflicts with main, and rewrote NEWS.

Now it LGTM.

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) July 21, 2026 04:59
@serhiy-storchaka
serhiy-storchaka merged commit 70f7c6c into python:main Jul 21, 2026
63 checks passed
@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

bedevere-app Bot commented Jul 21, 2026

Copy link
Copy Markdown

GH-154322 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 21, 2026
@miss-islington-app

Copy link
Copy Markdown

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

cherry_picker 70f7c6c0f2ddfd3b447946f1b926776b2a344703 3.13

@bedevere-app

bedevere-app Bot commented Jul 21, 2026

Copy link
Copy Markdown

GH-154323 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 21, 2026
@bedevere-app

bedevere-app Bot commented Jul 21, 2026

Copy link
Copy Markdown

GH-154330 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 21, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 21, 2026
…ne (GH-103926) (GH-154323)

"$" does not match before "\r" even in the MULTILINE mode, so such a
field was not found and the delimiter was guessed from character
frequencies instead, which could give a letter.
(cherry picked from commit 70f7c6c)

Co-authored-by: Zhou Wei <lilaboc.cn@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 21, 2026
…ne (GH-103926) (GH-154322)

"$" does not match before "\r" even in the MULTILINE mode, so such a
field was not found and the delimiter was guessed from character
frequencies instead, which could give a letter.
(cherry picked from commit 70f7c6c)

Co-authored-by: Zhou Wei <lilaboc.cn@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 21, 2026
…ne (GH-103926) (GH-154330)

"$" does not match before "\r" even in the MULTILINE mode, so such a
field was not found and the delimiter was guessed from character
frequencies instead, which could give a letter.

(cherry picked from commit 70f7c6c)

Co-authored-by: Zhou Wei <lilaboc.cn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants