← All recipes
Moderne licensed

Convert and/or ternary trick to conditional expression

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

Rewrite the legacy cond and val or fallback idiom as val if cond else fallback to avoid silent bugs when val is falsy.

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

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

mod config recipes pip install openrewrite-static-analysis