Replace getattr(x, 'attr') with x.attr

Proprietary

Replace getattr(x, "attr") calls with x.attr when the attribute name is a constant string that is a valid Python identifier. It leaves alone a shadowed getattr, a non-ASCII or name-mangled name, an object that would need parentheses, and a call holding comments.

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

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