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

PTH123 suggest to use pathlib.Path.open() which does not implement opener #7620

Closed
M5oul opened this issue Sep 23, 2023 · 0 comments · Fixed by #7637
Closed

PTH123 suggest to use pathlib.Path.open() which does not implement opener #7620

M5oul opened this issue Sep 23, 2023 · 0 comments · Fixed by #7637
Labels
bug Something isn't working

Comments

@M5oul
Copy link

M5oul commented Sep 23, 2023

Issue

In case an opener is used into open() function, for creating a file with certain permission for instance, ruff PTH123 suggests to use pathlib.Path.open() which does not implement the opener.

import os
dir_fd = os.open('somedir', os.O_RDONLY)
def opener(path, flags):
    return os.open(path, flags, dir_fd=dir_fd)

with open('spamspam.txt', 'w', opener=opener) as f:
    print('This will be written to somedir/spamspam.txt', file=f)
  • ruff version range: v0.0.276 - v0.0.291

Reference

Solution

  • Ruff can stop reporting it in case an opener is defined
  • Using # noqa: PTH123
konstin added a commit that referenced this issue Sep 25, 2023
…tter doesn't support all options

**Summary** Check that `closefd` and `opener` aren't being used with `builtin.open()` before suggesting `Path.open()` because pathlib doesn't support these arguments.

Closes #7620

**Test Plan** New cases in the fixture
@konstin konstin added the bug Something isn't working label Sep 25, 2023
konstin added a commit that referenced this issue Sep 26, 2023
…tter doesn't support all options (#7637)

**Summary** Check that `closefd` and `opener` aren't being used with
`builtin.open()` before suggesting `Path.open()` because pathlib doesn't
support these arguments.

Closes #7620

**Test Plan** New cases in the fixture.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants