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

PLW1514 does not check for uses of pathlib.Path.open() without an explicit encoding argument. #11263

Closed
yuji38kwmt opened this issue May 3, 2024 · 2 comments · Fixed by #11288
Assignees
Labels
good first issue Good for newcomers rule Implementing or modifying a lint rule

Comments

@yuji38kwmt
Copy link

Description

PLW1514 (unspecified-encoding) does not check for uses of pathlib.Path.open() without an explicit encoding argument.
But with Pylint, W1514 checks.

I expect Ruff to behave in the same way as Pylint.

sample.py

from pathlib import Path

with open("foo.txt") as f:
    f.readline()


with Path("foo.txt").open() as f:
    f.readline()

Checks with Ruff

$ ruff --version
ruff 0.4.2

$ ruff check --select PLW1514 --preview --output-format=concise --isolated
sample.py:3:6: PLW1514 `open` in text mode without explicit `encoding` argument
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Checks with Pylint

$ pylint --version
pylint 3.1.0
astroid 3.1.0
Python 3.12.1 (main, Feb  7 2024, 10:25:21) [GCC 11.4.0]

$ pylint sample.py --enable W1514 --disable C
************* Module sample
sample.py:3:5: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
sample.py:7:5: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)

------------------------------------------------------------------
Your code has been rated at 6.00/10 (previous run: 4.00/10, +2.00)
@zanieb zanieb added the rule Implementing or modifying a lint rule label May 3, 2024
@zanieb
Copy link
Member

zanieb commented May 3, 2024

Sounds good to me!

@zanieb zanieb added the good first issue Good for newcomers label May 3, 2024
@augustelalande
Copy link
Contributor

I'll implement this

dhruvmanila added a commit that referenced this issue May 9, 2024
… (`PLW1514`) (#11288)

<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

Resolves #11263

Detect `pathlib.Path.open` calls which do not specify a file encoding.

## Test Plan

Test cases added to fixture.

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants