-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make ARG002
compatible with EM101
when raising NotImplementedError
#13714
Make ARG002
compatible with EM101
when raising NotImplementedError
#13714
Conversation
|
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 looks good to me. Would you mind adding a test string with an f-string message?
crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs
Outdated
Show resolved
Hide resolved
|
||
let ast::Expr::Call(ast::ExprCall { | ||
func, arguments, .. | ||
}) = exception.as_ref() |
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.
Nit:
}) = exception.as_ref() | |
}) = &**exception |
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 see mixed usages of &**
and as_ref
throughout the code base. Out of curiosity, when is one used over the other? The general heuristic I've seen is *
and &
are recommended for simple stuff; and, once you start de-referencing and re-borrowing, that as_ref
is recommended if just to avoid needing to think about whatever container the value* is in.
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.
We used to use as_ref
but started to prefer dereferencing (except for Option
where you still need as_ref
and as_deref
) because it's possible that as_ref
becomes ambiguous if a new AsRef
implementation is added to a type. For example, String
has many as_ref
methods:
= note: multiple `impl`s satisfying `String: AsRef<_>` found in the following crates: `alloc`, `std`:
- impl AsRef<OsStr> for String;
- impl AsRef<Path> for String;
- impl AsRef<[u8]> for String;
- impl AsRef<str> for String;
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.
Oh interesting, that makes sense! Thank you!
crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.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 for the PR!
I made a few final changes:
- We should match the assignment target and argument node exactly. Previously, if either of them isn't a name node, the function would return true.
- Added some more test cases where
ARG002
should be raised
Going to wait for ecosystem checks and then merge. |
ARG002
compatible with EM101
when raising NotImplementedError
crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs
Outdated
Show resolved
Hide resolved
Thank you for fixing it up! I noticed the snapshot test didn't get updated after committing and thought "this can be Sunday's problem" 😅 |
Summary
This pull request resolves some rule thrashing identified in #12427 by allowing for unused arguments when using
NotImplementedError
with a variable per this comment.Note
This feels a little heavy-handed / edge-case-prone. So, to be clear, I'm happy to scrap this code and just update the docs to communicate that
abstractmethod
and friends should be used in this scenario (or similar). Just let me know what you'd like done!fixes: #12427
Test Plan
I added a test-case to the existing
ARG.py
file and ran...