ruff
ruff copied to clipboard
UP015 can't autofix if coming from pathlib.Path
This is with ruff==0.0.155
Consider this test file and ruff with UP015 activated.
import json
from pathlib import Path
filepath = Path('.' / 'afile.txt')
with filepath.open(mode='r') as f:
data = json.loads(f.read())
Running ruff on this outputs:
[2022-12-04][10:55:22][ruff::pyupgrade::plugins::redundant_open_modes][ERROR] Failed to remove parameter: Failed to locate start and end parentheses
Found 1 error(s).
test4.py:5:6: UP015 Unnecessary open mode parameters
1 potentially fixable with the --fix option.
pyupgrade refuses to change this, since it gives false positives on things like gzip.open (#1026). With #1027, ruff ≥ 0.0.156 also refuses to change this.