[Python-Dev] Possible py3k io wierdness (original) (raw)
brian at sweetapp.com brian at sweetapp.com
Sun Apr 5 00:35:32 CEST 2009
- Previous message: [Python-Dev] core python tests
- Next message: [Python-Dev] Possible py3k io wierdness
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hey,
I noticed that the call pattern of the C-implemented io libraries is as follows (translating from C to Python):
class _FileIO(object): def flush(self): if self.__IOBase_closed: raise ...
def close(self): self.flush() self.__IOBase_closed = True
class _RawIOBase(_FileIO): def close(self): # do close _FileIO.close(self)
This means that, if a subclass overrides flush(), it will be called after the file has been closed e.g.
import io class MyIO(io.FileIO): ... def flush(self): ... print('closed:', self.closed) ... f = MyIO('test.out', 'wb') f.close() closed: True
It seems to me that, during close, calls should only propagate up the class hierarchy i.e.
class _FileIO(object): def flush(self): if self.__IOBase_closed: raise ...
def close(self): _FileIO.flush(self) self.__IOBase_closed = True
I volunteer to change this if there is agreement that this is the way to go.
Cheers, Brian
- Previous message: [Python-Dev] core python tests
- Next message: [Python-Dev] Possible py3k io wierdness
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]