astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.51k stars 1.06k forks source link

autofix for flake8-use-pathlib (PTH) rules #2331

Open LefterisJP opened 1 year ago

LefterisJP commented 1 year ago

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.

sbrugman commented 1 year ago

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

sigma67 commented 4 months ago

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

charliermarsh commented 4 months ago

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.

JonathanPlasse commented 4 months ago

Should the tag type-inference be added?

sigma67 commented 4 months ago

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.

charliermarsh commented 4 months ago

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).