Replace setattr() with constant attribute assignment

Proprietary

Replace a setattr(x, "attr", value) statement with x.attr = value when the attribute name is a constant valid Python identifier. It leaves alone a shadowed setattr, a non-ASCII or name-mangled name, a call used as an expression, a call holding comments, and an object or value that may have side effects, since the assignment evaluates the value first.

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

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