Consider this code:
with open("tmp", "w") as f:
print(0)
print(1)
This works when saved as bug.py and run with python bug.py. But I can't copy and paste this code into a python interpreter:
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> with open("tmp", "w") as f:
... print(0)
... print(1)
File "<stdin>", line 3
print(1)
^
SyntaxError: invalid syntax
>>>
Where's the syntax error?
Edit: This applies more generally, as in
if False:
pass
pass