[Python S1481] Unused local variables should be remove with f-string format

  • versions used
    Sonar Could for Azure DevOps pull request
  • Code:
    style = "style = 'background-color : pink;'"
    #SonarCloud alert: Remove the unused local variable "style".
    key_name = k.replace("_", "\\_")
    #SonarCloud alert: Remove the unused local variable "key_name".
    body_text += f'''<tr {style if Counter(v.values()).get('FAIL', 0) != 0 else ''}><td>{key_name}</td><td>{Counter(v.values()).get('PASS', 0)}</td><td>{Counter(v.values()).get('FAIL', 0)}</td></tr>'''

The variable “style” and “key_name” are used in the f-string (body_text) but still get this error and block the PR

hello @wzmf399443,

welcome to our community!
I’m able to reproduce the false positive you reported and I created ticket SONARPY-815 to keep track of it.

Thanks a lot!

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