This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2010-02-05 21:28 by skrah, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg98909 - (view) Author: Stefan Krah (skrah) * (Python committer) 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) * (Python committer) Date: 2010-08-13 15:19
All of them should probably raise io.UnsupportedOperation instead (which inherits from both IOError and ValueError).
msg115531 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-03 22:55
See #9293, where there's a patch.
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52110
2010-09-03 22:55:51pitrousetstatus: open -> closed
resolution: duplicate
superseder: Unsupported IO operations should raise UnsupportedOperation
messages: + msg115531
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