[issue9293] Unsupported IO operations should raise UnsupportedOperation

Antoine Pitrou report at bugs.python.org
Sun Jul 18 16:09:31 CEST 2010


New submission from Antoine Pitrou <pitrou at free.fr>:

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

----------
components: IO, Library (Lib)
keywords: easy
messages: 110648
nosy: amaury.forgeotdarc, benjamin.peterson, haypo, pitrou
priority: normal
severity: normal
status: open
title: Unsupported IO operations should raise UnsupportedOperation
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9293>
_______________________________________


More information about the Python-bugs-list mailing list