Simplify String Length Comparison
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: simplify-string-len-comparison
Section titled “Sourcery refactoring id: simplify-string-len-comparison”Description:
Section titled “Description:”Changes an indirect comparison of a string’s length to 0 into a direct
comparison of the string to the empty string.
Before:
Section titled “Before:”if len(s) == 0: ...
if len(r) > 0: ...After:
Section titled “After:”if s == "": ...
if r != "": ...Explanation:
Section titled “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.