← All recipes
Moderne licensed

Use generator expression instead of list comprehension in iterable-accepting calls

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

Functions that consume iterables lazily (e.g. any, sum, sorted) do not need a list comprehension -- a generator expression suffices.

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

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

mod config recipes pip install openrewrite-static-analysis