wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

1948 Add Specifying Encoder Rule

Open GibranHL0 opened this issue 4 years ago • 8 comments

I have made things!

Closes #1948

Checklist

  • [x] I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • [x] I have created at least one test case for the changes I have made
  • [x] I have updated the documentation for the changes I have made
  • [x] I have added my changes to the CHANGELOG.md

Related issues

🙏 Please, if you or your company is finding wemake-python-styleguide valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/wemake-python-styleguide. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.

GibranHL0 avatar Jun 29 '21 00:06 GibranHL0

I used the following approach:

The open function has two ways to have the parameter encoding by the keyword encoding='utf-8' or being the fourth argument open('file.txt', 'r', -1, 'utf-8') . Then, I applied a visit_Call to check if the call is the function open and if it has the keyword encoding or a fourth parameter in the arguments.

GibranHL0 avatar Jun 29 '21 01:06 GibranHL0

For some reason our Actions do not start 🤔

sobolevn avatar Jun 29 '21 20:06 sobolevn

Maybe we should recreate this PR? Actions might ignore it for some reason.

sobolevn avatar Jun 29 '21 20:06 sobolevn

Sure, I will open a new PR with the changes you made.

GibranHL0 avatar Jun 29 '21 22:06 GibranHL0

I opened a new PR #2084 with the changes in the UnspecifiedEncodingViolation and the encoders to suppress warnings.

GibranHL0 avatar Jun 29 '21 23:06 GibranHL0

Thank you, I will close new one, let's keep more history here.

sobolevn avatar Jun 30 '21 09:06 sobolevn

Sure. Also, I committed a new change to the conf.py file because the encoder was not correct and it was causing warnings.

GibranHL0 avatar Jun 30 '21 16:06 GibranHL0

Encoding doesn't make sense when opened in binary mode. As the added tests don't have any binary mode tests I think this may be an oversight. What I'm not sure is if it should be OK to go without specifying encoding when in binary mode or if encoding=None is better. However, I don't know how difficult it is to make an exception for binary mode.

Sxderp avatar Oct 11 '21 17:10 Sxderp