classification
Title: fileio.c: ValueError vs. IOError with impossible operations
Type: behavior Stage:
Components: IO Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: pitrou Nosy List: amaury.forgeotdarc, pitrou, skrah, stutzbach
Priority: normal Keywords:

Created on 2010-02-05 21:28 by skrah, last changed 2010-08-13 15:19 by pitrou.

Messages (2)
msg98909 - (view) Author: Stefan Krah (skrah) Date: 2010-02-05 21:28
I think that certain FileIO methods should raise IOError instead of
ValueError when a file operation is attempted with the wrong mode.
The methods of IOBase are documented to raise IOError in these situations.


>>> import io
>>> f = io.open("testfile", "w")
>>> f.read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: not readable
>>> 
>>> f = io.FileIO("testfile", "w")
>>> f.read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: File not open for reading
msg113784 - (view) Author: Antoine Pitrou (pitrou) Date: 2010-08-13 15:19
All of them should probably raise io.UnsupportedOperation instead (which inherits from both IOError and ValueError).
History
Date User Action Args
2010-08-13 15:19:28pitrousetmessages: + msg113784
2010-08-02 19:17:50georg.brandlsetassignee: pitrou
2010-02-05 22:35:01pitrousetnosy: + amaury.forgeotdarc
2010-02-05 21:28:18skrahcreate