← All recipes
Moderne licensed

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

Recipe IDorg.openrewrite.python.cleanup.SimplifyConstantSumArtifactopenrewrite-static-analysis

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.

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.SimplifyConstantSum

If the recipe isn’t available locally, install it with:

mod config recipes pip install openrewrite-static-analysis