← All recipes
Moderne licensed

Replace string slicing with removeprefix/removesuffix

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

Replace if text.startswith(s): text = text[N:] with text = text.removeprefix(s) and the equivalent endswith pattern with removesuffix (Python 3.9+).

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

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

mod config recipes pip install openrewrite-static-analysis