← All recipes
Moderne licensed

Replace del x[:] with x.clear()

Recipe IDorg.openrewrite.python.cleanup.UseListClearArtifactopenrewrite-migrate-python

Use .clear() instead of del x[:] to empty a list. The method call is more explicit and idiomatic. Only a receiver whose type resolves to list or bytearray is rewritten, since del x[:] raises on a dict or deque that .clear() would empty.

Single recipepythonFURB131cleanupruffProprietary

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

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

mod config recipes pip install openrewrite-migrate-python
mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-python:RELEASE
mod config recipes jar install org.openrewrite:rewrite-python:RELEASE