-
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
When raising NotImplementedError
, ARG002 and EM101 are incompatible.
#12427
Comments
It's a bit of potentially unnecessary faff, but you can write these methods like this: def method(self, x):
_ = x
msg = "Something"
raise NotImplementedError(msg) |
I think rather than this, I would prefer suppressing one or the other of the rules (which is what I am doing now). |
I switched to |
Google's style guide recommends def method(self, x):
del x # unused
msg = "Something"
raise NotImplementedError(msg) |
Interesting. I guess this should be at least mentioned in the ruff documentation of these errors as well. Also, these all feel like workarounds for an issue that I feel doesn't really needs to be flagged in the first place. |
It seems reasonable to avoid this false positive in ARG002. I'm not sure how hard it will be. |
Here's the rule, here's the original Python is_stub_function, and here's Ruff's is_stub. It seems like a simple fix would be expanding the definition of But, going down that route, it's likely worth documenting what the cut-off for a "stub" is. That if you need things like Stmt::Assign(StmtAssign { value, .. }) => {
matches!(value.as_ref(), Expr::StringLiteral(_))
} Does that sound reasonable? |
I don't think this will work completely because it'll start giving false negatives. What we need to do is to add a new condition which will be checked if the first condition is false. This will check whether there are exactly two statements and they match the following pattern: variable = <string | f-string>
raise NotImplementedError(variable) Note that this condition should only be checked locally to |
Yes, that's fair! My inclination to modify But, to your point, it's probably better not to pollute the definition of How does having a very specific |
We can discuss the naming in the PR but yeah that sounds about right |
ARG002 is usually not raised in methods that immediately raise a
NotImplementedError
, but does if there is some other code in the method. However, EM101 enforces adding the error message into a separate variable, which is then seen as "code".The result of this is that there is no way to write such a method without raising one or the other issue. See example below.
running
ruff check test_file.py --select ARG002 --select EM101
on the code snippet above results inThe text was updated successfully, but these errors were encountered: