-
Notifications
You must be signed in to change notification settings - Fork 31
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
Ignore C812 when only one function argument #59
Comments
+1 |
Why? The purpose of the trailing comma here is to cut down on diff noise in the future. It is totally plausible that some code passes one parameter when first written and then 3 in the iteration. |
I am all for trailing commas to reduce diff noise, thank you for developing this plugin! 😍 When we were trying to bring it into our flake8 setup, its flagging some cases similar to the above which I would not expect. For example when building some Django ORM queries we have code like:
I realise it would be valid syntax (in 3.7 at least) to have the Do you think it is feasible for the linter to allow for such syntax without having to add |
What would the algorithm be @9thbit ? Because in your example if I replace BTW: I am not involved in this project, only another happy user. It is my hope that asking questions here will lead to the right outcome. |
Absolutely, or even removing |
Give the code a read, it is fairly clear I think. Right now there is minimal state gathering. I could see a more complicated version that differentiated between one argument functions and multi argument functions. Then you could ignore the one argument error if you liked. That is one solution. I am not sure at the moment how to determine the number of arguments a function requires but it should be possible to look at the parse tree and see how many are being passed in currently. A place where the current checker does something weird is requiring a comma after "kwargs" which is definitely not going to see more arguments after it in most code. |
black also requires a trailing comma after **kwargs (in py3.6+ only) |
My opinion on this matter is that it's not about differentiating between 1 or more arguments, but more about the difference between fixed or changing argument counts. If a function call requires two arguments, period, then I almost feel like the trailing comma hints at a possibility of giving more. But doing so would cause an immediate error, which makes me feel like a trailing comma should be at least a warning and certainly not a recommendation. Yes, of course, the function signature could some day change allowing (maybe even requiring) one more argument. But I feel that this would be such a profound impact that reducing the diff noise by one line is probably not going to matter... |
While I like this, I have also started using a "workaround" that also helps identify the string (or long bit) as a single argument. I'd much rather see #58 implemented. The below doesn't throw any errors. It works out nicely for "segregating" arguments. I believe it also works for implicit concatenation, but I don't use that in my code. logger.debug(
(
"Really long string " +
"explicitly joined"
),
) |
I agree, this would be nice. There are cases where you know it's incredibly unlikely that a function is going to get another argument, so it just looks a bit ugly there. |
I'd like to ignore the error when there's only one argument to the function. For example:
The text was updated successfully, but these errors were encountered: