Python merging`if`statement logic leads to many false positives

We use sonarsource Version: 1.21.0. in our azure pipeline and it works great. However, I find myself spending time repeatedly tagging the same issue as false positive.

Either the logic around if statement in python forgets about line lengths or is unaware how the walrus operator works.

if is_first_condition and is_second_condition:
    if, text_variable, flags=re.IGNORECASE):

Merging these two lines into a single line will a) make it less readable and b) break the line length limit. However, sonarcloud keeps recommending to merge these lines.

The second false positive is around the walrus operator. It is not possible to chain a walrus operator with other logical conditions (code will not compile). However, sonarcloud keeps recommending that I merge if statments.

if match:
    if match2 :=,

Here two examples:
Long Lines
too long line
Walrus Operator
walrus operator

Here the advice provided:

hello @Ed123 ,

Welcome to our community and thanks for reporting those false positives.
To keep track of your feedback I created ticket SONARPY-904.

1 Like