Simplify Empty Collection 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-empty-collection-comparison
Section titled “Sourcery refactoring id: simplify-empty-collection-comparison”Description:
Section titled “Description:”Replace an empty collection comparison with a more idiomatic unary operator.
Before:
Section titled “Before:”if a == "": do_anything()
while l == []: handle(l)After:
Section titled “After:”if not a: do_anything()
while not l: handle(l)Explanation:
Section titled “Explanation:”This refactoring follows the PEP 8 Programming Recommendations, specifically the recommendation that
For sequences, (strings, lists, tuples), use the fact that empty sequences are false
in the context of comparisons.