Merge nested with statements into one
Recipe ID
org.openrewrite.python.cleanup.MergeNestedWithStatementsArtifactopenrewrite-migrate-pythonCombine directly nested with statements into a single with when the outer body contains only the inner with. An async with is left alone, as is a comment between the two, an outer with holding other statements, and a pair whose context managers the merge would leave split across lines outside parentheses.
Single recipepythoncleanupruffSIM117Proprietary
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.MergeNestedWithStatementsIf 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