Skip to content

gh-138005: Document that CSV skipinitialspace=True and delimiter=' ' require quotation for empty fields #138006

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 4 commits into
base: main
Choose a base branch
from

Conversation

maurycy
Copy link
Contributor

@maurycy maurycy commented Aug 20, 2025

Please see for the code:

  • cpython/Modules/_csv.c

    Lines 1253 to 1267 in 7dc42b6

    if (!field_len && dialect->delimiter == ' ' && dialect->skipinitialspace) {
    if (dialect->quoting == QUOTE_NONE ||
    (field == NULL &&
    (dialect->quoting == QUOTE_STRINGS ||
    dialect->quoting == QUOTE_NOTNULL)))
    {
    PyErr_Format(self->error_obj,
    "empty field must be quoted if delimiter is a space "
    "and skipinitialspace is true");
    return 0;
    }
    quoted = 1;
    }
    rec_len = join_append_data(self, field_kind, field_data, field_len,
    &quoted, 0);

Please see the test:

The behavior is intentional since gh-115721, so the only sensible route is to update the docs.


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

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

I think this is too verbose. The note takes up a lot of space and attracts a disproportionate amount of attention. Most users will never encounter this, and if they do, this behavior is expected and therefore does not require any special explanation.

Could you please limit yourself to one short sentence? That such CSV files cannot contain empty fields.

@maurycy
Copy link
Contributor Author

maurycy commented Aug 21, 2025

I think this is too verbose. The note takes up a lot of space and attracts a disproportionate amount of attention. Most users will never encounter this, and if they do, this behavior is expected and therefore does not require any special explanation.

Could you please limit yourself to one short sentence? That such CSV files cannot contain empty fields.

Thank you for taking a look. Made it much shorter:

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge 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.

2 participants