bers
(bers)
March 28, 2023, 4:08pm
1
Language: Python
Rule: S5655
false-positive since typing.Sequence
is an alias of collections.abc.Sequence
, so the two should be considered equivalent
SonarLint for VS Code v3.16.0, not connected
from typing import Sequence as Sequence1
# typing.py: `Sequence = _alias(collections.abc.Sequence, 1)`
from collections.abc import Sequence as Sequence2 # isort: skip
def fun1(ints: Sequence1[int]) -> None:
print(ints)
def fun2(ints: Sequence2[int]) -> None:
print(ints)
fun1((1,)) # this works
fun2((1,)) # this works, but SonarLint reports python:S5655
Related issue (for dict
):
Python 3.9
SonarLint 6.6.0.45106
In the following code sample, SonarLint reports violations of S5655 (Arguments given to functions should be of an expected type) and S5890 (Values assigned to variables should match their type annotations) in the lines marked with the comment FP:
from collections.abc import Mapping
from typing import Any
def f(mapping: Mapping[str, Any]) -> dict[str, Any]:
return dict(mapping)
f({"a": 2}) # FP S5655
d1: Mapping[str, Any] = {"a": 2} # FP S5890
f(d1)
d…
https://sonarsource.atlassian.net/jira/software/c/projects/SONARPY/issues/SONARPY-998
Hi @bers ,
Thanks for reporting this.
Indeed this seem to be related to this already reported problem.
I updated our ticket in the backlog.
Similarly to the other thread, as a workaround, I suggest adding sonar.python.version: "3.9"
into SonarLint analyzer properties. This should solve your FPs.