(An Unofficial) Python Reference Wiki

"clearly marked experimental"

5f42

Also note that the syntax only allows a single target. IOW this is valid::

with foo as bar:
    pass

But this is not::

with foo as bar, bletch:
    pass

You can write this instead::

with foo as (bar, bletch):
    pass

The reason is to leave a possibility open in the future to extend the syntax to allow multiple context guards; this could be spelled in one of the following ways::

with G1, G2 as x1, x2:
    pass

or::

with G1 as x1, G2 as x2:
    pass