Variable wrongly marked as not used for walrus operator

def func():
    for _ in range(var := 2):
        ...

    print(var)

result:

Please make sure to read this post before raising a thread here:

Specifically, we’re missing what products/versions you’re using

I am using SonarLint 6.7.0.45926 for Pycharm

Hi @Grzegorz_Ryznar ,

Thanks a lot for the reproducer and to report us this false positive.
I created SONARPY-1040 to fix this FP.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.