wemake-python-styleguide
wemake-python-styleguide copied to clipboard
1948 Add Specifying Encoder Rule
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.
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.
For some reason our Actions do not start 🤔
Maybe we should recreate this PR? Actions might ignore it for some reason.
Sure, I will open a new PR with the changes you made.
I opened a new PR #2084 with the changes in the UnspecifiedEncodingViolation and the encoders to suppress warnings.
Thank you, I will close new one, let's keep more history here.
Sure. Also, I committed a new change to the conf.py file because the encoder was not correct and it was causing warnings.
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.