-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[flake8-use-pathlib
] Add autofixes for PTH100
, PTH106
, PTH107
, PTH108
, PTH110
, PTH111
, PTH112
, PTH113
, PTH114
, PTH115
, PTH117
, PTH119
, PTH120
#19213
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
Conversation
CodSpeed Instrumentation Performance ReportMerging #19213 will not alter performanceComparing Summary
|
@ntBre I was wondering if we need a new test, there are none for |
Since we have already done tests in import os.path, pathlib
from os.path import abspath
path_to_file = "../path/to/file"
os.path.abspath("../path/to/file")
os.path.abspath(pathlib.Path("../path/to/file")))
abspath(path=path_to_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I gave this a quick skim and it looks reasonable to me. I also had an idea for helping with the benchmark regression.
I don't think we need to move the tests around. It seems okay, if not ideal, that they are scattered in these various files. I think the existing tests, plus the new tests you added in the previous PR, should give us good enough coverage.
I'll take another look at this once CI is passing to make sure all the new snapshots look reasonable.
if checker | ||
.semantic() | ||
.resolve_qualified_name(&call.func) | ||
.is_none_or(|qualified_name| qualified_name.segments() != ["os", "path", fn_name]) | ||
.is_none_or(|qualified_name| qualified_name.segments() != full_import) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may want to pass the QualifiedName
or even the segments
into each of these rule functions after computing it in expression.rs
. Calling resolve_qualified_name
repeatedly stood out to me in the benchmark regression.
it seems to work a little differently 😁 |
2710d87
to
c2705b1
Compare
it seems we will need to revise all the parameters, I found a bug in the python documentation |
Wow, nice catch! |
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PTH120 | 568 | 0 | 0 | 568 | 0 |
PTH110 | 546 | 0 | 0 | 546 | 0 |
PTH100 | 208 | 0 | 0 | 208 | 0 |
PTH119 | 208 | 0 | 0 | 208 | 0 |
PTH113 | 186 | 0 | 0 | 186 | 0 |
PTH107 | 170 | 0 | 0 | 170 | 0 |
PTH112 | 88 | 0 | 0 | 88 | 0 |
PTH111 | 74 | 0 | 0 | 74 | 0 |
PTH108 | 28 | 0 | 0 | 28 | 0 |
PTH114 | 22 | 0 | 0 | 22 | 0 |
PTH117 | 12 | 0 | 0 | 12 | 0 |
PTH115 | 6 | 0 | 0 | 6 | 0 |
PTH106 | 6 | 0 | 0 | 6 | 0 |
I would suggest treating the |
Is such a regression acceptable? there are many autofixes for rules after all |
crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_abspath.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good! The one thing we probably should do is add a preview
test for these other rules on their existing files. So basically copy this test and enable preview:
ruff/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs
Lines 19 to 24 in 1eff030
#[test_case(Path::new("full_name.py"))] | |
#[test_case(Path::new("import_as.py"))] | |
#[test_case(Path::new("import_from_as.py"))] | |
#[test_case(Path::new("import_from.py"))] | |
#[test_case(Path::new("use_pathlib.py"))] | |
fn rules(path: &Path) -> Result<()> { |
I think that should cover the preview behavior for all of these.
also, can you please update that table from #2331? |
windows runner 🫡 |
flake8-use-pathlib
] Add autofixes for PTH100
, PTH106
, PTH107
, PTH108
, PTH110
, PTH111
, PTH112
, PTH113
, PTH114
, PTH115
, PTH117
, PTH118
, PTH119
flake8-use-pathlib
] Add autofixes for PTH100
, PTH106
, PTH107
, PTH108
, PTH110
, PTH111
, PTH112
, PTH113
, PTH114
, PTH115
, PTH117
, PTH118
, PTH119
, PTH120
flake8-use-pathlib
] Add autofixes for PTH100
, PTH106
, PTH107
, PTH108
, PTH110
, PTH111
, PTH112
, PTH113
, PTH114
, PTH115
, PTH117
, PTH118
, PTH119
, PTH120
flake8-use-pathlib
] Add autofixes for PTH100
, PTH106
, PTH107
, PTH108
, PTH110
, PTH111
, PTH112
, PTH113
, PTH114
, PTH115
, PTH117
, PTH119
, PTH120
…re_help * 'main' of https://github.com/astral-sh/ruff: (34 commits) [docs] add capital one to who's using ruff (astral-sh#19248) [`pyupgrade`] Keyword arguments in `super` should suppress the `UP008` fix (astral-sh#19131) [`flake8-use-pathlib`] Add autofixes for `PTH100`, `PTH106`, `PTH107`, `PTH108`, `PTH110`, `PTH111`, `PTH112`, `PTH113`, `PTH114`, `PTH115`, `PTH117`, `PTH119`, `PTH120` (astral-sh#19213) [ty] Do not run `mypy_primer.yaml` when all changed files are Markdown files (astral-sh#19244) [`flake8-bandit`] Make example error out-of-the-box (`S412`) (astral-sh#19241) [`pydoclint`] Make example error out-of-the-box (`DOC501`) (astral-sh#19218) [ty] Add "kind" to completion suggestions [ty] Add type information to `all_members` API [ty] Expand API of `all_members` to return a struct [ty] Ecosystem analyzer PR comment workflow (astral-sh#19237) [ty] Merge `ty_macros` into `ruff_macros` (astral-sh#19229) [ty] Fix `ClassLiteral.into_callable` for dataclasses (astral-sh#19192) [ty] `dataclasses.field` support (astral-sh#19140) [ty] Fix panic for attribute expressions with empty value (astral-sh#19069) [ty] Return `CallableType` from `BoundMethodType.into_callable_type` (astral-sh#19193) [`flake8-bugbear`] Support non-context-manager calls in `B017` (astral-sh#19063) [ty] Improved diagnostic for reassignments of `Final` symbols (astral-sh#19214) [ty] Use full range for assignment definitions (astral-sh#19211) [`pylint`] Update `missing-maxsplit-arg` docs and error to suggest proper usage (`PLC0207`) (astral-sh#18949) [ty] Add `set -eu` to mypy-primer script (astral-sh#19212) ... # Conflicts: # crates/ty_python_semantic/src/types/class.rs
Summary
Part of #2331
Test Plan
update snapshots for preview mode