classification
Title: Unsupported IO operations should raise UnsupportedOperation
Type: behavior Stage:
Components: IO, Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, pitrou, skrah, stutzbach, vstinner
Priority: normal Keywords: easy, patch

Created on 2010-07-18 14:09 by pitrou, last changed 2010-09-05 23:05 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
unsupported.patch pitrou, 2010-09-03 19:41
Messages (4)
msg110648 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-18 14:09
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 "<stdin>", line 1, in <module>
IOError: not writable

With:
>>> open("LICENSE", "rb").write(b"")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
io.UnsupportedOperation: write

Or:
>>> io.StringIO().fileno()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
io.UnsupportedOperation: fileno

Or, unfortunately:

>>> open("LICENSE", "rb", buffering=0).write(b"")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: File not open for writing
msg110650 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-18 14:38
Another kind of unsupported operation is non-absolute seeking on a TextIOWrapper:

>>> open("LICENSE").seek(1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: can't do nonzero cur-relative seeks
msg115490 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-03 19:41
Here is a patch.
msg115677 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-05 23:05
Committed in r84544.
History
Date User Action Args
2010-09-05 23:05:17pitrousetstatus: open -> closed
resolution: fixed
messages: + msg115677
2010-09-03 22:56:15pitrousetnosy: + stutzbach, skrah
2010-09-03 22:55:51pitroulinkissue7862 superseder
2010-09-03 19:41:15pitrousetfiles: + unsupported.patch
keywords: + patch
messages: + msg115490
2010-07-18 14:38:17pitrousetmessages: + msg110650
2010-07-18 14:09:29pitroucreate