Issue 9940: Strange error reporting with "with" statement (original) (raw)

Under 3.2 and 3.1:

with open("foo", "wb") as x: pass ... with open("foo", "wb") as (x, y): pass ... Traceback (most recent call last): File "", line 1, in io.UnsupportedOperation: read

Similar oddities under 2.7:

with open("foo", "wb") as (x, y): pass ... Traceback (most recent call last): File "", line 1, in IOError: File not open for reading with io.open("foo", "wb") as (x, y): pass ... Traceback (most recent call last): File "", line 1, in io.UnsupportedOperation: read

Of course, you get the same error with:

f = open('foo', 'wb') x, y = f Traceback (most recent call last): File "", line 1, in IOError: File not open for reading

i.e. the tuple assignment iterates over the file, and calls readline()