← All recipes
Moderne licensed

Replace setattr() with constant attribute assignment

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

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.

Single recipepythonB010cleanupruffProprietary

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

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