False positive on python3.10 type generics python:S5644

My team has recently set up Sonarqube Enterprise Edition Version 9.4 (build 54424) but have some false positives on our python3.10 code.

Our sonar-project.properties (key removed):

sonar.projectKey=...
sonar.python.version=3.10

I made an MRE like this, which makes use of type being a typing.Generic. It gets reported as python:S5644 “Item operations should be done on objects supporting them.”

type_alias = type[Exception]

I am aware that I can use the “Resolve as false positive” option, but I was more fearful that I have somehow not correctly set up the python version correctly.

Does anyone have thoughts or suggestions on this? It is annoying to get things such as this with python3.10
Fix this invalid "|" operation between incompatible types (str and str).

from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from _typeshed import OpenBinaryMode, OpenTextMode

mode: "OpenBinaryMode" | "OpenTextMode" # false positive here

Hi @spagh-eddie ,
Thanks a lot for reporting those two false positives!
I created SONARPY-1007 and SONARPY-1008 to keep track of those.
Fixes should be available within next version of SonarQube

1 Like

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