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.
Created on 2009年12月26日 20:48 by blep, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (8) | |||
|---|---|---|---|
| msg96892 - (view) | Author: Baptiste Lepilleur (blep) | Date: 2009年12月26日 20:48 | |
The io.IOBase class doc says: """Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise IOError in this case.""" But the io.IOBase.close() method document says: """Once the file is closed, any operation on the file (e.g. reading or writing) will raise an IOError.""" which unlike the class doc is not conditional about the behavior... Experimentation (see below) show that I get a ValueError in practice (python 3.1, but also true for 2.6) with io.BufferedWriter and io.StringIO objects. >>> with open( 'dummy', 'wb') as f: ... pass ... >>> f.write( b'' ) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: write to closed file >>> f.writable() Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: I/O operation on closed file >>> import io >>> s = io.StringIO() >>> s.close() >>> s.read() Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: I/O operation on closed file |
|||
| msg96926 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2009年12月27日 21:57 | |
Should all these ValueErrors be turned into IOErrors? |
|||
| msg96927 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年12月27日 22:00 | |
I think we raise ValueError because that's already what 2.x does with plain file objects. Also, it's true that it's a programming error (using a closed file) and not really an "IO error". Simplest would be to fix the docs for the io module, IMHO. |
|||
| msg96942 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2009年12月28日 08:14 | |
I agree; though I would wish for a bit finer-grained I/O related exceptions... |
|||
| msg96972 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年12月28日 22:11 | |
> I agree; though I would wish for a bit finer-grained I/O related > exceptions... I agree with that. It probably needs someone to shepherd the idea to python-dev so as to get it accepted. |
|||
| msg97123 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2010年01月01日 23:28 | |
Note that one of the reasons for the slightly wishy-washy phrasing in the docs is to give other implementations a bit more freedom in the way way they handle these error cases. Agreed that the main reason is the one Antoine gave though - the ValueError is looking at things from the point of view that the program passed in a closed file object when an open one was needed. |
|||
| msg166203 - (view) | Author: Kirubakaran Athmanathan (kirubakaran) | Date: 2012年07月23日 03:16 | |
Looks like this was fixed in 3.3 in the commit 72890:a22d94547570 Should this issue be closed? |
|||
| msg166216 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2012年07月23日 09:42 | |
Indeed. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:55 | admin | set | github: 51827 |
| 2012年07月23日 09:42:09 | pitrou | set | status: open -> closed resolution: out of date messages: + msg166216 stage: resolved |
| 2012年07月23日 03:16:43 | kirubakaran | set | nosy:
+ kirubakaran messages: + msg166203 |
| 2010年01月01日 23:28:07 | ncoghlan | set | nosy:
+ ncoghlan messages: + msg97123 |
| 2009年12月28日 22:11:46 | pitrou | set | messages: + msg96972 |
| 2009年12月28日 08:14:24 | georg.brandl | set | assignee: georg.brandl -> pitrou |
| 2009年12月28日 08:14:13 | georg.brandl | set | messages: + msg96942 |
| 2009年12月27日 22:00:29 | pitrou | set | messages: + msg96927 |
| 2009年12月27日 21:57:04 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc, pitrou messages: + msg96926 |
| 2009年12月26日 20:49:17 | blep | set | title: Behavio of operations on a closed file object is not documented correctly -> Behavior of operations on a closed file object is not documented correctly |
| 2009年12月26日 20:48:34 | blep | create | |