Python:S5655 incorrectly applying to Enum on startup of VS Code

Please provide

  • Operating system:
    • Windows - VS Code
  • SonarLint plugin version:
    • SonarQube for IDE v4.13.0
  • Programming language you’re coding in:
    • Python
  • Is connected mode used:
    • No and SonarServer

And a thorough description of the problem / question:

I have the following code:

from http import HTTPStatus

def response(message: str, status_code: HTTPStatus):
    #This is a test.
    pass

response("Blah", HTTPStatus.OK)

When launching VS Code, the SonarQube plugin says that my call to response with HTTPStatus.OK is a violation of RSPEC-5655. This doesn’t make sense as I am literally passing in an HTTPStatus equivalent object.

If I change status_code to be of type int, then the warning goes away. Then if I change it back the warning flashes for a second before going away in that file. It stays gone until I restart VS Code.

This seems like a bug in SonarQube’s rule parsing.

Hi there!

Thanks for reporting this behavior. I think it has two parts—one about a False Positive report from the rule and another about issues coming and suddenly disappearing.

For the latter, we have just released SonarQube for VSCode (formerly SonarLint) v4.13.1. Could you please update and let us know if your issue persists?

All the best,
Sophio

The issue now does reappear, so yes, the only remaining issue is the false positive.
Thank you.

Great!

Could you please share a screenshot where you see the false positive? I will flag this for the relevant team in the meantime.

All the best,
Sophio

Here is an example of the warning appearing in my project.
It does NOT seem to appear in a standalone project where I attempt to replicate the issue, which is odd.

I was able to replicate it.
Ensuring that the rule Python:S5655 is enabled, I create a new file with the original code in VS Code and change the type HTTPStatus to a str in __response. This (correctly) causes an error to appear.

Then revert the type back to HTTPStatus. The error appears and persists through restarts.

Hello @jbvirt,

Thank you one more time for reporting this false positive.
I have created the SONARPY-2421 ticket to fix the issue.

Thanks,
Maksim Grebeniuk