Simplify sum(1 for x in items if cond) to sum(bool(cond) for x in items)

Proprietary

Replace sum(1 for x in items if cond) with sum(bool(cond) for x in items) by moving the filter condition into a bool() wrapper. It only fires for the integer literal 1 and where sum and bool resolve to the builtins.

org.openrewrite.python.cleanup.SimplifyConstantSum
mod run . --recipe=org.openrewrite.python.cleanup.SimplifyConstantSum

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.