-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[flake8-use-pathlib] Add autofix for PTH101, PTH104, PTH105, PTH121
#19404
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
# Conflicts: # crates/ruff_linter/src/checkers/ast/analyze/expression.rs # crates/ruff_linter/src/preview.rs # crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs # crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs # crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs
|
sorry for #19298 😕 |
|
Do you know what happened on the other PR? I just saw something similar on #19338. I'll try to take a look soon, but it might not be until next week. Thanks for working on these! |
it was my mistake |
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PTH101 | 26 | 0 | 0 | 26 | 0 |
| PTH104 | 20 | 0 | 0 | 20 | 0 |
| PTH105 | 2 | 0 | 0 | 2 | 0 |
|
@chirizxc |
I think so, but I won't promise😴 |
ntBre
left a comment
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.
The implementation looked good to me, but do you know what happened with the missing snapshots? It looks like we lost a bunch of violations even though their Python files aren't modified. It might be a minor issue with the is_rule_enabled checks, hopefully.
...lake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__full_name.py.snap
Show resolved
Hide resolved
Initial tests in the files are not correct |
|
These tests were taken from the original flake8-use-pathlib repository, now if you try to run these tests you will get Missing argument, since they require two arguments in general |
|
Ohhh, they have the wrong number of arguments? Okay, this is probably good to go then. I'll take one more look at the snapshots. Thank you for clarifying and for fixing that pre-existing bug! |
|
Hmm, on second thought, maybe we still want diagnostics in theses cases and just to suppress the fixes. What do you think about that? I think the diagnostics are still useful, but fixing could be dangerous since there's another error there already. |
|
I think it's a bit weird to suggest diagnostic when the code can't run due to an error |
in some rules it already works like that, we can just take the behavior from them, if not, then we need to think🤔 |
I can see what you mean, but in general I think we try to show as many diagnostics as possible. The case I usually picture is someone getting a different diagnostic about the wrong number of arguments (maybe from a type checker or LSP), fixing that, and then a new Ruff diagnostic appears. Instead we'd prefer for the Ruff diagnostic to be there from the start. They are using (or trying to use) an In this case it also preserves the existing behavior, which is nice since adding an autofix usually shouldn't modify the other behavior of the rule.
Which rules do you mean here? |
Misspelled, meant IF this behavior is already used in other rules, we should do the same thing |
|
done |
ntBre
left a comment
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.
Thank you!
* main: [ty] Fix narrowing and reachability of class patterns with arguments (#19512) [ty] Implemented partial support for "find references" language server feature. (#19475) [`flake8-use-pathlib`] Add autofix for `PTH101`, `PTH104`, `PTH105`, `PTH121` (#19404) [`perflint`] Parenthesize generator expressions (`PERF401`) (#19325) [`pep8-naming`] Fix `N802` false positives for `CGIHTTPRequestHandler` and `SimpleHTTPRequestHandler` (#19432) [`pylint`] Handle empty comments after line continuation (`PLR2044`) (#19405) Move concise diagnostic rendering to `ruff_db` (#19398) [ty] highlight the argument in `static_assert` error messages (#19426) [ty] Infer single-valuedness for enums based on `int`/`str` (#19510) [ty] Restructure submodule query around `File` dependency [ty] Make `Module` a Salsa ingredient [ty] Reachability analysis for `isinstance(…)` branches (#19503) [ty] Normalize single-member enums to their instance type (#19502) [ty] Invert `ty_ide` and `ty_project` dependency (#19501) [ty] Implement mock language server for testing (#19391) [ty] Detect enums if metaclass is a subtype of EnumType/EnumMeta (#19481) [ty] perform type narrowing for places marked `global` too (#19381)
Summary
Part of #2331
Test Plan
cargo nextest run flake8_use_pathlib