[Python-Dev] Possible py3k io wierdness (original) (raw)
Brian Quinlan brian at sweetapp.com
Sun Apr 12 12:49:37 CEST 2009
- Previous message: [Python-Dev] Possible py3k io wierdness
- Next message: [Python-Dev] [RELEASED] Python 3.1 alpha 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I've added a new proposed patch to: http://bugs.python.org/issue5700
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() super().flush() def _close(self): print( super()._close()
class MyClass(FileIO, DebugClass): # whatever order makes sense ...
m = MyClass(...) m.close()
Will call:
IOBase.close()
DebugClass.flush() # FileIO has no .flush method
IOBase.flush()
FileIO._close()
DebugClass._close()
IOBase._close()
Cheers, Brian
- Previous message: [Python-Dev] Possible py3k io wierdness
- Next message: [Python-Dev] [RELEASED] Python 3.1 alpha 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]