Environment:
- Operating system: macOS 14.5
- SonarLint plugin version: 10.7.0.78874
- Programming language you’re coding in: python
- Is connected mode used: no
- Connected to SonarCloud or SonarQube (and which version):
Description of the problem:
SonarLint incorrectly flags the assignment target of the walrus operator :=
as unused when used in a generator expression inside a call to any()
or all()
.
Presumably the special case described in PEP 572 — Scope of the target is not implemented.
In the snippet below, taken from the text of PEP 572, comment
is flagged as being unused with a reference to python:S1481
.
lines = ['# comment line', 'normal line']
if any((comment := line).startswith('#') for line in lines):
print("First comment:", comment)
else:
print("There are no comments")
Expected behaviour:
SonarLint correctly calculates the scope of the variable and recognises that it is used.