Issue 9293: Unsupported IO operations should raise UnsupportedOperation (original) (raw)
Some of them currently raise IOError. Fortunately, UnsupportedOperation inherits from IOError, which means compatibility can be preserved.
Contrast:
open("LICENSE").write("bar") Traceback (most recent call last): File "", line 1, in IOError: not writable
With:
open("LICENSE", "rb").write(b"") Traceback (most recent call last): File "", line 1, in io.UnsupportedOperation: write
Or:
io.StringIO().fileno() Traceback (most recent call last): File "", line 1, in io.UnsupportedOperation: fileno
Or, unfortunately:
open("LICENSE", "rb", buffering=0).write(b"") Traceback (most recent call last): File "", line 1, in ValueError: File not open for writing
Another kind of unsupported operation is non-absolute seeking on a TextIOWrapper:
open("LICENSE").seek(1, 1) Traceback (most recent call last): File "", line 1, in IOError: can't do nonzero cur-relative seeks