[Python-Dev] Possible py3k io wierdness

brian at sweetapp.com brian at sweetapp.com
Sun Apr 5 00:35:32 CEST 2009


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


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /