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

Make unspecified-encoding work for pathlib.Path.write_text() #4945

Closed
trym-b opened this issue Sep 1, 2021 · 0 comments · Fixed by #4946
Closed

Make unspecified-encoding work for pathlib.Path.write_text() #4945

trym-b opened this issue Sep 1, 2021 · 0 comments · Fixed by #4946
Labels
Enhancement ✨ Improvement to a component
Milestone

Comments

@trym-b
Copy link

trym-b commented Sep 1, 2021

Current problem

I very much like unspecified-encoding for enforcing the encoding parameter when using open, however it does not seem to work with the more modern way of writing to files through pathlib, which also has an encoding argument.

Here is an example

from pathlib import Path


def open_test() -> None:
    with open("some_file") as open_file:
        print(open_file.read())


def read_text_test() -> None:
    print(Path("some_file").read_text())

When running the following command, only the open call without encoding will be detected by pylint.

$ pylint ./test_pylint_pathlib.py --disable missing-module-docstring --disable missing-function-docstring
************* Module test_pylint_pathlib
test_pylint_pathlib.py:5:9: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)

------------------------------------------------------------------
Your code has been rated at 8.33/10 (previous run: 8.33/10, +0.00)

Desired solution

I want calls to pathlib.Path.write_text() / pathlib.Path.read_text() to also be detected by pylint.

Basically something like this as output of the code above:

$ pylint ./test_pylint_pathlib.py --disable missing-module-docstring --disable missing-function-docstring
************* Module test_pylint_pathlib
test_pylint_pathlib.py:5:9: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
test_pylint_pathlib.py:10:28: W1514: Using read_text without explicitly specifying an encoding (unspecified-encoding)

------------------------------------------------------------------
Your code has been rated at 8.33/10 (previous run: 8.33/10, +0.00)

Additional context

No response

@trym-b trym-b added Enhancement ✨ Improvement to a component Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 1, 2021
@Pierre-Sassoulas Pierre-Sassoulas removed the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 1, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 1, 2021
The ``unspecified-encoding`` checker now also checks calls to ``pathlib.Path().read_text()``
and ``pathlib.Path().write_text()``
This closes pylint-dev#4945
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.0 milestone Sep 1, 2021
Pierre-Sassoulas pushed a commit that referenced this issue Sep 1, 2021
The ``unspecified-encoding`` checker now also checks calls to ``pathlib.Path().read_text()``
and ``pathlib.Path().write_text()``
This closes #4945
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants