Simplify sum(1 for x in items if cond) to sum(bool(cond) for x in items)
Recipe ID
org.openrewrite.python.cleanup.SimplifyConstantSumArtifactopenrewrite-static-analysisReplace 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.
Single recipeProprietary
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.python.cleanup.SimplifyConstantSumIf the recipe isn’t available locally, install it with:
mod config recipes pip install openrewrite-static-analysis