MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
187 stars 19 forks source link

[Adjust Rule] SIM300 false positive with literals on both sides #155

Open ghost opened 2 years ago

ghost commented 2 years ago

Desired change

Explanation

These comparisons are pointless, but swapping them around (only to be told to swap them around again after) is also pointless.

Example

Example 1

if "a" == "b":
    pass
SIM300: Use '"b" == "a"' instead of '"a" == "b"' (Yoda-conditions)

Example 2

if 1 == 2:
    pass
SIM300: Use '2 == 1' instead of '1 == 2' (Yoda-conditions)
MartinThoma commented 2 years ago

Hm... Although the error message is misleading, I would still say that such code should be fixed. Instead of comparing constants, I'd recommend to use the result of the comparison directly. Or do you see a case where you would want to keep the constant comparison?