Merge nested with statements into one

Proprietary

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

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

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