ruff icon indicating copy to clipboard operation
ruff copied to clipboard

autofix for flake8-use-pathlib (PTH) rules

Open LefterisJP opened this issue 3 years ago • 6 comments

I enabled PTH rules and there was a few hits in rotki's codebase.

This is a rule I woud like to enforce but there is quite many places it hit and I suppose at least some of the rules should be autofixable. So if possible it would be cool to have ruff do it for us.

LefterisJP avatar Jan 29 '23 23:01 LefterisJP

See https://github.com/charliermarsh/ruff/pull/2348

sbrugman avatar Jan 30 '23 11:01 sbrugman

Since the issue is still open, is this still on the table? I think most PTH rules have no autofixes yet

It seems there are no more open PRs on this topic

sigma67 avatar May 21 '24 08:05 sigma67

Certainly on the table, just needs someone to work on it. It may also be limited by our ability to do program-wide analysis beyond simple fixes.

charliermarsh avatar May 21 '24 11:05 charliermarsh

Should the tag type-inference be added?

JonathanPlasse avatar May 21 '24 12:05 JonathanPlasse

It may also be limited by our ability to do program-wide analysis beyond simple fixes.

Most of the fixes seem simple enough to me, i.e.

PTH102 "os.mkdir() should be replaced by Path.mkdir()"

os.mkdir(var, kwargs)

becomes

Path(var).mkdir(kwargs)

I may be missing something - not sure how it could affect a broader scope of code.

sigma67 avatar May 21 '24 12:05 sigma67

Yeah we can do simple stuff like tha, although I think the spirit of the rule is that you'd changed var to be of type Path more holistically in the code, then do var.mkdir(kwargs).

charliermarsh avatar May 21 '24 13:05 charliermarsh