[Python-Dev] Possible py3k io wierdness

Brian Quinlan brian at sweetapp.com
Sun Apr 5 12:56:47 CEST 2009

Antoine Pitrou wrote:
> Brian Quinlan <brian <at> sweetapp.com> writes:
>> I don't see why this is helpful. Could you explain why 
>> _RawIOBase.close() calling self.flush() is useful?
> I could not explain it for sure since I didn't write the Python version.
> I suppose it's so that people who only override flush() automatically get the
> flush-on-close behaviour.

But the way that the code is currently written, flush only gets called 
*after* the file has been closed (see my original example). It seems 
very unlikely that this is the behavior that the subclass would want/expect.

So any objections to me changing IOBase (and the C implementation) to:

     def close(self):
         """Flush and close the IO object.

         This method has no effect if the file is already closed.
         if not self.__closed:
-                self.flush()
+                IOBase.flush(self)
             except IOError:
                 pass  # If flush() fails, just give up
             self.__closed = True


More information about the Python-Dev mailing list