Simplify String Length Comparison¶
Sourcery refactoring id: simplify-string-len-comparison
¶
Description:¶
Changes an indirect comparison of a string's length to 0
into a direct
comparison of the string to the empty string.
Before:¶
if len(s) == 0:
...
if len(r) > 0:
...
After:¶
if s == "":
...
if r != "":
...
Explanation:¶
This refactoring avoids an unnecessary calculation and keeps the logic in the domain of string types. It tends to unlock further improvements to string comparisons.