[Python-Dev] Possible py3k io wierdness (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Sun Apr 5 01:23:06 CEST 2009
- Previous message: [Python-Dev] Possible py3k io wierdness
- Next message: [Python-Dev] Possible py3k io wierdness
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi!
<brian sweetapp.com> writes:
class RawIOBase(FileIO):
FileIO is a subclass of _RawIOBase, not the reverse:
issubclass(io.RawIOBase, io.FileIO) False issubclass(io.FileIO, io.RawIOBase) True
I do understand your surprise, but the Python implementation of IOBase.close() in _pyio.py does the same thing:
def close(self) -> None:
"""Flush and close the IO object.
This method has no effect if the file is already closed.
"""
if not self.__closed:
try:
self.flush()
except IOError:
pass # If flush() fails, just give up
self.__closed = True
Note how it calls self.flush()
and not IOBase.flush(self)
.
When writing the C version of the I/O stack, we tried to keep the semantics the
same as in the Python version, although there are a couple of subtleties.
Your problem here is that it's IOBase.close() which calls your flush() method,
but FileIO.close() has already done its job before and the internal file
descriptor has been closed (hence self.closed
is True). In this particular
case, I advocate overriding close() as well and call your flush() method
manually from there.
Thanks for your feedback!
Regards
Antoine.
- Previous message: [Python-Dev] Possible py3k io wierdness
- Next message: [Python-Dev] Possible py3k io wierdness
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]