Skip to content

gh-132813: Fix the csv documentation for quoting and escaping #133209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Apr 30, 2025

quotechar and new-line characters are always quoted or escaped. escapechar is always escaped.


📚 Documentation preview 📚: https://cpython-previews--133209.org.readthedocs.build/

quotechar and new-line characters are always quoted or escaped.
escapechar is always escaped.
@vadimkantorov
Copy link

What can also be surprising is different behavior for quotechar="" and quotechar=None. I would make them behave the same (currently quotechar="" is not permitted), but it's very subjective indeed

@serhiy-storchaka
Copy link
Member Author

It was. In the past, "" and "\0" were interpreted as None for delimiter, quotechar and escapechar. But it was confusing, and it was impossible to use the null character as the delimiter or whatever.

@vadimkantorov
Copy link

@serhiy-storchaka IIUC, quote_char=None is accepted for QUOTE_NONE, but quote_char="" is not, because there is a check that if it's a str, it must be a 1-char str. For me the fact that quote_char=None is accepted, but quote_char="" is not is strange (not talking here about the null character "\0", just about empty string)

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@serhiy-storchaka serhiy-storchaka requested a review from a team May 13, 2025 10:35
A one-character string used by the writer to escape the *delimiter*,
the *quotechar*, ``'\r'``, ``'\n'`` and any of the characters in
*lineterminator* if *quoting* is set to :const:`QUOTE_NONE`,
the *quotechar* if *doublequote* is :const:`False`,
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand this part of the sentence in the original, nor the addition below.

Copy link
Member Author

Choose a reason for hiding this comment

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

How would you write it?

Different characters are escaped depending on different conditions:

  • if quoting is set to :const:QUOTE_NONE, it escapes delimiter, quotechar, etc.
  • if doublequote is False, it escapes quotechar.

Copy link

Choose a reason for hiding this comment

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

Perhaps:

A one-character string for escaping. If quoting is set to :const:QUOTE_NONE, it escapes delimiter, quotechar,  ``'\r'``, ``'\n'`` and any of the characters in *lineterminator*. If doublequote is False, it escapes quotechar

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

I am assuming that the fact changes are correct. I code not parse one sentence before and less so now. I am guessing that it needs to be split into 2 sentences.

@bedevere-app
Copy link

bedevere-app bot commented May 13, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@vadimkantorov
Copy link

vadimkantorov commented May 13, 2025

It would be nice if the docs mentioned explicitly that quotechar=None is also allowed. Currently:
image

which says that "empty" is not allowed, whatever that might be meaning (and many people would consider None to also qualify as "empty")

@serhiy-storchaka
Copy link
Member Author

This what this PR does.

@serhiy-storchaka
Copy link
Member Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented May 20, 2025

Thanks for making the requested changes!

@terryjreedy: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from terryjreedy May 20, 2025 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting change review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy