Skip to content

nested-with

Pythonstyleno fixdefault: offpython/ruff

Reports a with whose only statement is another with, when both are sync or both are async.

One with can open several context managers (with a, b:), which saves an indent level and the long lines that nesting forces.

To fix, join the two into one with.

Reported
...
...
with a:
...
pass
...
python:
lint:
rules:
nested-with: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line nested-with in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff SIM117 full