So I have this simple example of a with
statement.
It works in Python 3.8 and 3.9:
class Foo:
def __enter__(self, *args):
print("enter")
def __exit__(self, *args):
print("exit")
with Foo() as f, Foo() as b:
print("Foo")
Output (as expected):
enter
enter
Foo
exit
exit
But if I add parentheses like this it only works in Python 3.9:
class Foo:
def __enter__(self, *args):
print("enter")
def __exit__(self, *args):
print("exit")
with (Foo() as f, Foo() as b):
print("Foo")
Output in 3.8:
File "foo.py", line 8
with (Foo() as f, Foo() as b):
^
SyntaxError: invalid syntax
I know, I could just remove the parentheses but I don't understand why it works in Python 3.9 in the first place. I could not find the relevant change log.