[flake8-use-pathlib] Add fix for PTH123#20169
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PTH123 | 1684 | 0 | 0 | 1684 | 0 |
|
I'm not sure which tests should be included in the tests files, but i tested in this file: The first line with # ruff: noqa: SIM115, PLW1514, FBT003
import builtins
from pathlib import Path
_file = "file.txt"
_x = ("r+", -1)
r_plus = "r+"
builtins.open(file=_file) # noqa: PTH123
builtins.open(file=_file)
Path(_file).open()
open(mode="wb", file=_file) # noqa: PTH123
open(mode="wb", file=_file)
Path(_file).open(mode="wb")
open(mode="r+", buffering=-1, file=_file, encoding="utf-8") # noqa: PTH123
open(mode="r+", buffering=-1, file=_file, encoding="utf-8")
Path(_file).open(mode="r+", buffering=-1, encoding="utf-8")
open(_file, "r+", -1, None, None, None) # noqa: PTH123
open(_file, "r+", -1, None, None, None)
Path(_file).open("r+", -1, None, None, None)
open(_file, "r+", -1, None, None, None, closefd=True, opener=None) # noqa: PTH123
open(_file, "r+", -1, None, None, None, closefd=True, opener=None)
Path(_file).open("r+", -1, None, None, None)
open(_file, mode="r+", buffering=-1, encoding=None, errors=None, newline=None) # noqa: PTH123
open(_file, mode="r+", buffering=-1, encoding=None, errors=None, newline=None)
Path(_file).open(mode="r+", buffering=-1, encoding=None, errors=None, newline=None)
open(buffering=- 1, file=_file, encoding= "utf-8") # noqa: PTH123
open(buffering=- 1, file=_file, encoding= "utf-8")
Path(_file).open(buffering=-1, encoding="utf-8")
open(_file, "r+", - 1, None, None, None, True, None) # noqa: PTH123
open(_file, "r+", - 1, None, None, None, True, None)
Path(_file).open("r+", -1, None, None, None)
open(_file, "r+ ", - 1) # noqa: PTH123
open(_file, "r+ ", - 1)
Path(_file).open("r+ ", -1)
open(_file, f" {r_plus} ", - 1) # noqa: PTH123
open(_file, f" {r_plus} ", - 1)
Path(_file).open(f" {r_plus} ", -1)
# Only diagnostic
open()
open(_file, *_x)
open(_file, "r+", unknown=True)
open(_file, "r+", closefd=False)
open(_file, "r+", None, None, None, None, None, None, None) |
ntBre
left a comment
There was a problem hiding this comment.
Thanks! I think you could add those tests to a new file called PTH123.py. It looks like there's some overlap with the test you added in import_from.py, so we could either add the additional file or just add more cases there?
This looks good to me overall, just a few minor suggestions.
|
i don't think that's the way to fix it either |
ntBre
left a comment
There was a problem hiding this comment.
Thanks! Just two more minor things, but I think this looks good otherwise.
|
I guess I forgot about that, thanks for the change |
Summary
Part of #2331
Test Plan
cargo nextest run flake8_use_pathlib