← All recipes
Moderne licensed

Replace len() emptiness check with truthiness

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

Rewrite `len(seq) > 0 / len(seq) != 0 to seq and len(seq) == 0 to not seq`, leveraging Python's built-in truthiness for collections.

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

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

mod config recipes pip install openrewrite-static-analysis