False-positive type mismatch with `collections.abc.Sequence` (e.g., python:S5655)

  • 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):

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.