Skip to content
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

[Enhancement] newline argument for csv.reader() #9422

Open
opk12 opened this issue Feb 8, 2024 · 0 comments
Open

[Enhancement] newline argument for csv.reader() #9422

opk12 opened this issue Feb 8, 2024 · 0 comments
Labels
Needs decision 🔒 Needs a decision before implemention or rejection Needs specification 🔐 Accepted as a potential improvement, and needs to specify edge cases, message names, etc. Proposal 📨

Comments

@opk12
Copy link

opk12 commented Feb 8, 2024

Current problem

The doc for csv.reader() warns that not passing newline can cause issues.

A csvfile is most commonly a file-like object or list. If csvfile is a file object, it should be opened with newline=''

If newline='' is not specified, newlines embedded inside quoted fields will not be interpreted correctly, and on platforms that use \r\n linendings on write an extra \r will be added. It should always be safe to specify newline='', since the csv module does its own (universal) newline handling.

Desired solution

Warn if csv.reader() is not being passed newline explicitly.

Additional context

I found this in a student homework. Is it in-scope for pylint to warn? Note that refurb did not warn.

import csv
result = {}

def f():
    with open("/tmp/file1", 'r') as route:
        for row in csv.reader(route, delimiter="\t"):
            counter = counter + 1
            result[row[0]] = row[1]
        ...
    return counter

f()
@opk12 opk12 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 8, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Proposal 📨 Needs decision 🔒 Needs a decision before implemention or rejection Needs specification 🔐 Accepted as a potential improvement, and needs to specify edge cases, message names, etc. and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs decision 🔒 Needs a decision before implemention or rejection Needs specification 🔐 Accepted as a potential improvement, and needs to specify edge cases, message names, etc. Proposal 📨
Projects
None yet
Development

No branches or pull requests

2 participants