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

Require specifying encoding when using "open" (re: PEP597) #1948

Open
Sxderp opened this issue Mar 16, 2021 · 5 comments · May be fixed by #2082
Open

Require specifying encoding when using "open" (re: PEP597) #1948

Sxderp opened this issue Mar 16, 2021 · 5 comments · May be fixed by #2082
Labels
rule request Adding a new rule

Comments

@Sxderp
Copy link
Contributor

Sxderp commented Mar 16, 2021

Rule request

Inspired by https://www.python.org/dev/peps/pep-0597

The PEP is still draft, but I think WPS can implement before adoption. Even if the PEP is rejected I think this is a good idea.

Required specifying "encoding" to open. Even if it's just None.

Thesis

Not specifying the encoding could be considered a bug. Making the effort to choose which encoding is better. At the moment there is no builtin "locale" so we have to settle for None or call locale.getpreferredencoding() all the time. The second option is a bit clumbersome.

## Wrong
with open('filename.txt') as fd:
    fd.read()

## Correct
with open('filename.txt', encoding='ascii') as fd:
  fd.read()

with open('filename.txt', encoding='utf8') as fd:
  fd.read()

# Unfortunately we have to settle for "None" to indicate "locale".
with open('filename.txt', encoding=None) as fd:
  fd.read()

Reasoning

Everything described in the PEP.

@Sxderp Sxderp added the rule request Adding a new rule label Mar 16, 2021
@sobolevn
Copy link
Member

Great idea, I will totally do this (either here or in typed-linter that I am developing right now)!

Why not just implementing it here? Because typed-linter will support auto-fixing problems. And this looks like it can be autofixed.

@GibranHL0
Copy link
Contributor

I'd like to take this issue as well, pls 😌

@GibranHL0
Copy link
Contributor

#2082 Opened

@sobolevn sobolevn mentioned this issue Jun 30, 2021
4 tasks
@lensvol
Copy link
Collaborator

lensvol commented Oct 9, 2021

Is this still opened?

@sobolevn
Copy link
Member

sobolevn commented Oct 9, 2021

There's a PR for it: #2082

I will merge it into 0.16.0 later this week.

@sobolevn sobolevn added this to the Version 0.16 milestone Oct 9, 2021
@sobolevn sobolevn self-assigned this Oct 9, 2021
@sobolevn sobolevn linked a pull request Oct 9, 2021 that will close this issue
4 tasks
@sobolevn sobolevn removed their assignment Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule request Adding a new rule
Projects
None yet
4 participants