-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[pep8_naming
] Add fixes N804
and N805
#10215
[pep8_naming
] Add fixes N804
and N805
#10215
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
ANN101 | 20 | 10 | 10 | 0 | 0 |
N805 | 4 | 2 | 2 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+3 -3 violations, +0 -0 fixes in 2 projects; 41 projects unchanged)
bokeh/bokeh (+2 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ tests/unit/bokeh/test_transform.py:65:20: A002 Argument `object` is shadowing a Python builtin - tests/unit/bokeh/test_transform.py:65:20: A002 Argument `object` is shadowing a Python builtin + tests/unit/bokeh/test_transform.py:72:27: A002 Argument `object` is shadowing a Python builtin - tests/unit/bokeh/test_transform.py:72:27: A002 Argument `object` is shadowing a Python builtin
zulip/zulip (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ zerver/models/realms.py:1:1: D100 Missing docstring in public module - zerver/models/realms.py:1:1: D100 Missing docstring in public module
Changes by rule (2 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
A002 | 4 | 2 | 2 | 0 | 0 |
D100 | 2 | 1 | 1 | 0 | 0 |
let binding = scope | ||
.get_all(&first_parameter.name) | ||
.map(|id| semantic.binding(id)) | ||
.find(|b| b.kind.is_argument())?; |
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.
Can you see if Renamer::rename
would be useful here?
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.
Renamer::rename
would rename all first_parameter.name
bindings. I wanted to only renaming references to the argument binding, like this:
Lines 241 to 245 in 90651a2
114 |- def bad_method(this): | |
115 |- this = this | |
114 |+ def bad_method(self): | |
115 |+ this = self | |
116 116 | this |
But I didn't know the Renamer
existed, and from what I've tested Pyright lsp also renames with the same logic as the Renamer
. I've updated the PR to use it.
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.
This is nice work, great job figuring this out.
## Summary This PR fixes for `invalid-first-argument` rules. The fixes rename the first argument of methods and class methods to the valid one. References to this argument are also renamed. Fixes are skipped when another argument is named as the valid first argument. The fix is marked as unsafe due The functions for the `N804` and `N805` rules are now merged, as they only differ by the name of the valid first argument. The rules were moved from the AST iteration to the deferred scopes to be in the function scope while creating the fix. ## Test Plan `cargo test`
Summary
This PR fixes for
invalid-first-argument
rules.The fixes rename the first argument of methods and class methods to the valid one. References to this argument are also renamed.
Fixes are skipped when another argument is named as the valid first argument.
The fix is marked as unsafe due
The functions for the
N804
andN805
rules are now merged, as they only differ by the name of the valid first argument.The rules were moved from the AST iteration to the deferred scopes to be in the function scope while creating the fix.
Test Plan
cargo test