[Python-Dev] Possible py3k io wierdness

Brian Quinlan brian at sweetapp.com
Sun Apr 12 12:49:37 CEST 2009

I've added a new proposed patch to:

The idea is:
- only IOBase implements close() (though a subclass can override close
   without causing problems so long as it calls super().close() or
   calls .flush() and ._close() directly)
- change IOBase.close to call .flush() and then ._close()
- .flush() invokes super().flush() in every class except IOBase
- ._close() invokes super()._close() in every class except IOBase
- FileIO is implemented in Python in _pyio.py so that it can have the
   same base class as the other Python-implemented files classes
- tests verify that .flush() is not called after the file is closed
- tests verify that ._close()/.flush() calls are propagated correctly

On nice side effect is that inheritance is a lot easier and MI works as 
expected i.e.

class DebugClass(IOBase):
   def flush(self):
     print(<some debug info>)
   def _close(self):
     print(<some debug info>

class MyClass(FileIO, DebugClass): # whatever order makes sense

m = MyClass(...)
# Will call:
#   IOBase.close()
#   DebugClass.flush()  # FileIO has no .flush method
#   IOBase.flush()
#   FileIO._close()
#   DebugClass._close()
#   IOBase._close()


More information about the Python-Dev mailing list