MartinThoma / flake8-simplify

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

SIM103: Unnecessary if-else to return boolean #3

Closed MartinThoma closed 4 years ago

MartinThoma commented 4 years ago

Rule

Do not use an if-else block when you can directly return the condition.

Example

# Bad
if condition:
    return True
else
    return False

# Good
return bool(condition)
tolomea commented 2 years ago

The description here is good, but the actual implementation suggests using "return condition" instead which is behaviour changing. Similarly the suggestion for "return not not condition" is "return condition" which is also behaviour changing.