Make ARG002 compatible with EM101 when raising NotImplementedError#13714
Make ARG002 compatible with EM101 when raising NotImplementedError#13714dhruvmanila merged 11 commits intoastral-sh:mainfrom
ARG002 compatible with EM101 when raising NotImplementedError#13714Conversation
|
MichaReiser
left a comment
There was a problem hiding this comment.
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.
Nit:
| }) = exception.as_ref() | |
| }) = &**exception |
There was a problem hiding this comment.
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.
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.
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
dhruvmanila
left a comment
There was a problem hiding this comment.
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
ARG002should 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
NotImplementedErrorwith 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
abstractmethodand 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.pyfile and ran...