Use augmented assignment

Proprietary

Rewrite x = x op y as x op= y for +, -, *, / and %. It only fires where x is a side-effect-free name whose type resolves to an immutable builtin such as int or str, since op= mutates a list in place. A walrus (x := x + y) is left alone.

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

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