pylint-errors

W0124 (confusing-with-statement)

:x: Problematic code:

with open('file.txt', 'w') as fh1, fh2:
    pass

:heavy_check_mark: Correct code:

from contextlib import ExitStack
with ExitStack() as stack:
    fh1 = stack.enter_context(open('file1.txt', 'w'))
    fh2 = stack.enter_context(open('file2.txt', 'w'))

Rationale:

Emitted when a with statement component returns multiple values and uses name binding with as only for a part of those values, as in with ctx() as a, b. This can be misleading, since it’s not clear if the context manager returns a tuple or if the node without a name binding is another context manager.