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.

For a dataclass type this is still a problem.

@dataclass
class IOConf:
    sb_source: str
    container: str

def get_servicebus_receiver(client: ServiceBusClient, stage_config: IOConf, dlq: bool = False) -> ServiceBusReceiver:
   ...


with ServiceBusClient.from_connection_string(stage.servicebus_conn_str) as client:
    receiver = get_servicebus_receiver(client, stage, dlq=True)

mod_stage = replace(stage)
mod_stage.batch_size = 500
mod_stage.max_wait = 5

with ServiceBusClient.from_connection_string(stage.servicebus_conn_str) as client:
    receiver = get_servicebus_receiver(client, mod_stage, dlq=True) # python:S5655

Hi @icfly2,

The relevant ticket is still open.

 
HTH,
Ann

And will there be any progress? It was started a year and a half ago…