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
False Positive - Mismatch in multiple assignment #8991
Comments
|
It looks like you are getting this error because the function can return 4, 5, or 10 values depending on what value of My suggestion is either refactor the function so that it always returns the same number of parameters (even if some of them are empty or unused), or use LGTM facilities to disable this query. |
|
Thanks for your review of this @aeisenberg. I agree that it's difficult for LGTM to figure out whether the number of values returned match the number expected as there are a number of use cases for this function. I will proceed with error suppression as I'd rather not refactor the code if there is no error. The issue I have with error suppression is that to suppress an alert the # lgtm [py/mismatched-multiple-assignment] comment must be on the same line as the offending code. If the offending code runs across multiple lines (as is common when using an auto formatter like Black) the suppression comment does not work. Is there a way around this that does not involve having a very long line of code? |
|
I don't know the answer to this. I'll ask the team that maintains LGTM. |
|
@MatthewReid854 The suppression comment needs to be on the line where the alert starts, which is line 392 in this case. Note that you don't have to include the query identifier ( You can also use |
|
Thanks @aibaars for the tip about the shorthand comment for alert suppression. Unfortunately this does nothing to resolve the problem of needing the query identifier comment on the same line that the offending code starts. |
|
The shorthand forms There is very little development on LGTM these days as the focus of the team is on CodeScanning these days. That said, it might still be useful to open an issue (or a pull request) to request improvements to Trying to look for a query identifier on a next comment line may be a little tricky as it may be hard to distinguish a wrapped identifier from an unrelated comment that happens to be on the next line. An alternative would be to make an That way the following two examples would work the same: # lgtm [py/mismatched-multiple-assignment]
a,b=1,2,3and a,b=1,2,3 # lgtm [py/mismatched-multiple-assignment]I think this can be achieved by modifying codeql/python/ql/src/analysis/AlertSuppression.ql Lines 43 to 48 in ca2959c
|
Does this mean that this false positive is unlikely to be fixed anytime soon? If so, how does that square with the invitation in the documentation to file issues for false positives?
I hope there is agreement that flagging a, b = foo()as a mismatch is a false positive if it can be proven that |
@hannes-ucsc The comment above is related to the request to improve the suppression syntax for LGTM. Since the teams focus is not on LGTM this is unlikely to be changed. Both LGTM and CodeScanning use the CodeQL static analyser under the hood. CodeQL is under active development in this repository and the team greatly values false positive reports. You're absolutely right that this is a false positive if |
False positive for "Mismatch in multiple assignment" in Python.
A mismatch in multiple assignment can occur when the number of values assigned does not match the number of variables to which they are assigned. For example a,b=1,2,3 would cause this error in Python.
The false positive occurs when the number of variables is not directly assigned, but instead assigned to a function such as:
out1,out2 = myfunction(in1,in2,in3)
This is not direct assignment of variables but LGTM triggers a false positive on some occasions when this syntax is used.
URL to the alert on the project page on LGTM.com is available from here
In this file, there are 18 alerts and they are all for the same style of false positive.
Another issue is that to suppress an alert the # lgtm [py/mismatched-multiple-assignment] comment must be on the same line as the offending code. If the offending code runs across multiple lines (as is common when using an auto formatter like Black) the suppression comment does not work.
The text was updated successfully, but these errors were encountered: