Error in Sonarcloud Code Smell Analysis

Template for a good new topic, formatted with Markdown:

  • ALM used GitHub
  • Python
  • Only if the SonarCloud project is public, the URL
    • Not public
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
foo = bar if bar else '-'
Remove this expression which always evaluates to "true".

This is incorrect. bar may be None, in which case the if evaluates to False and foo is set to ‘-’.

Hello @glennmglazer,

Thank you for the report. I tried to replicate your issue with this simple function:

def test(bar):
    foo = bar if bar else '-'
    return foo

However, I do not observe the false positive you are mentioning. I should be able to better investigate the issue if you are willing to share the function that contains this particular line.



Hi, Sylvain.

Thanks for getting back to me. In the time since I posted, the error went away. I can’t repro either.

Feel free to close/ignore this.



That’s a bit frightful to hear, we do not want to have issues appear and disappear for no reason. Did this particular issue disappear after some related code was changed?

In any case, feel free to post again here if it is raised again.