← All recipes
Moderne licensed

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

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

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.

Single recipepythoncleanupruffB009Proprietary

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

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