-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PEP 597, require encoding kwarg in open call (and other calls that delegate to io.open) #3826
Comments
# bad
with open(filename) as f:
...
# bad
with open(filename, encoding=None) as f:
...
# good
with open(filename, encoding="utf8", errors="surrogateescape") as f:
...
# good
locale_encoding = getattr(io, "LOCALE_ENCODING", None)
with open(filename, encoding=locale_encoding) as f:
... |
@graingert thanks! |
@hippo91 can you allocate a pylint feature id for me? |
@graingert sorry for the delay. What do you mean by |
I think I mean a message id? http://pylint.pycqa.org/en/latest/technical_reference/features.html |
@graingert i think a new message id is necessary for this case. Something around |
Note that it's not just open, eg os.fdopen |
I really like this one, I had the problem multiple time for windows/mac users, that would be really helpful. I'd also use an error code for that one. Regarding the message id, what about |
@Pierre-Sassoulas let's go for |
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes pylint-dev#3826
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes PyCQA#3826
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes pylint-dev#3826
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes pylint-dev#3826
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes pylint-dev#3826
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes pylint-dev#3826
* Add unspecified-encoding checker #3826 This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes #3826 * Update tests to conform to unspecified-encoding With addition of the unspecified-encoding checker calls of open() need an encoding argument. Where necessary this argument has been added, or the message has been disabled. This also includes small linting changes to a small number of tests. Their test-data has been updated to reflect new line numbers. * Update scripts to conform to unspecified-encoding With addition of the unspecified-encoding checker calls of open() need an encoding argument. Where necessary this argument has been added. * Update pylint to conform to unspecified-encoding With addition of the unspecified-encoding checker calls of open() need an encoding argument. Where necessary this argument has been added. Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Read more about the warning here: pylint-dev/pylint#3826 Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
A new warning appeared from pylint when calling "tox -e lint" on the "develop" branch with id "unspecified-encoding", I read about the warning and it make sense. Read more about the warning here: pylint-dev/pylint#3826 Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Should also With import pathlib
pathlib.Path("/some/file").read_text() gives no |
I forget that one the most |
I think you're right, I never used it myself so I did not think of adding it. Do you want to do the change @graingert ? :) |
You probably see it/have seen it already: For |
Sorry I should have mentioned it in the issue, read_text was where I first noticed the problem because I assumed that was utf8 but knew open wasn't! |
A new warning appeared from pylint when calling "tox -e lint" on the "develop" branch with id "unspecified-encoding", I read about the warning and it make sense. Read more about the warning here: pylint-dev/pylint#3826 Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
A new warning appeared from pylint when calling "tox -e lint" on the "develop" branch with id "unspecified-encoding", I read about the warning and it make sense. Read more about the warning here: pylint-dev/pylint#3826 Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
[PEP 597](https://www.python.org/dev/peps/pep-0597/) adds an additional warning when using open() without specifying an explicit encoding. This was added to pylint in pylint-dev/pylint#3826 and eventually broke our build as a new warning.
Pylint 2.10 added new default checks [1]: unspecified-encoding: Emitted when open() is called without specifying an encoding [2] [1] https://pylint.pycqa.org/en/latest/whatsnew/2.10.html [2] pylint-dev/pylint#3826 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Pylint 2.10 introduced new checker unspecified-encoding: > Added unspecified-encoding: Emitted when open() is called without specifying an encoding https://pylint.pycqa.org/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-10-0 pylint-dev/pylint#3826 https://www.python.org/dev/peps/pep-0597/ Fixes: freeipa#244 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Pylint 2.10 introduced new checker unspecified-encoding: > Added unspecified-encoding: Emitted when open() is called without specifying an encoding See pylint-dev/pylint#3826 See https://www.python.org/dev/peps/pep-0597/ Fixes: fleet-commander#279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Pylint 2.10 introduced new checker unspecified-encoding: > Added unspecified-encoding: Emitted when open() is called without specifying an encoding See pylint-dev/pylint#3826 See https://www.python.org/dev/peps/pep-0597/ Fixes: fleet-commander#279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Pylint 2.10 introduced new checker unspecified-encoding: > Added unspecified-encoding: Emitted when open() is called without specifying an encoding See pylint-dev/pylint#3826 See https://www.python.org/dev/peps/pep-0597/ Fixes: #279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Is your feature request related to a problem? Please describe
there's a proposal to deprecate not passing an encoding to
open(...)
https://www.python.org/dev/peps/pep-0597/#motivation
Describe the solution you'd like
raise a warning similar to subprocess-run-check
Additional context
Add any other context about the feature request here.
The text was updated successfully, but these errors were encountered: