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

Proprietary

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. A statement holding comments is left alone.

org.openrewrite.python.cleanup.UseListClear
mod run . --recipe=org.openrewrite.python.cleanup.UseListClear

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.