2 rules added to Python analysis to detect constant boolean expressions due to operands' type incompatibility

Hello Python developers,

The latest updates on Python analyzer help you make your Python code more reliable and detects boolean expressions always returning the same result because of their operands’ types.

This is achieved thanks to these 2 new rules:

  • S3403: Identity operators should not be used with dissimilar types
  • S2159: Silly equality checks should not be made

Here are some examples in action:

  • Type of “target_temperature” is int, so the expression “target_temperature is None” is always false:
  • The string returned by the function “str(…)” is always different from 0 and can’t be equal to 0. So the first check is useless without impact but the second one prevent to reach the body of the if statement:

These bug detection rules are available on SonarCloud. For SonarQube users, you can get them now by upgrading to v2.6 of the Python analysis engine.