[Python-Dev] file() (original) (raw)
Guido van Rossum guido at python.org
Mon Jun 12 21:37:55 CEST 2006
- Previous message: [Python-Dev] file()
- Next message: [Python-Dev] External Package Maintenance
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
No, because ValueError is the better exception for an invalid mode string.
On 6/12/06, Georg Brandl <g.brandl at gmx.net> wrote:
Guido van Rossum wrote: > On 6/12/06, Georg Brandl <g.brandl at gmx.net> wrote: >> Guido van Rossum wrote: >> > Yup, although it's a change in behavior that would need to be studied >> > carefully for backwards incompatibilities. Usually it's given as a >> > constant, so there won't be any problems; but there might be code that >> > receives a mode string and attempts to test its validity by trying it >> > and catching IOError, such code would have to be changed. >> > >> > --Guido >> > >> > On 6/12/06, Kristján V. Jónsson <kristjan at ccpgames.com> wrote: >> >> I notice that file() throws an IOError when it detects an invalid mode >> >> string. Wouldn't a ValueError be more appropriate? >> > >> >> The situation is even more complex with the current trunk. open() raises >> ValueError if it detects an invalid the mode string, such as universal >> newline mode and a writable mode combined (the definition of >> what is invalid has been made stricter, the mode string now must begin >> with r, w, a or U), but it raises IOError if the OS call to fopen() fails >> because of an invalid mode string. This might need unification. > > That would be hard to fix unless we get rid of the stdio-based > implementation (which I intend to do in Py3k). I say we leave it alone > for now -- fopen() can fail for any number of platform-dependent > reasons and we can't really expect to do look-before-you-leap on this.
One option would be to raise IOError in the former case too. That's what I meant with "unification". Cheers, Georg
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] file()
- Next message: [Python-Dev] External Package Maintenance
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]