[issue5700] io.FileIO calls flush() after file closed

Brian Quinlan report at bugs.python.org
Sun Apr 12 13:50:41 CEST 2009


Brian Quinlan <brian at sweetapp.com> added the comment:

>> - FileIO is implemented in Python in _pyio.py so that it can have the
>>    same base class as the other Python-implemented files classes

> Is it really necessary (e.g. to pass the tests)?

It is necessary to make MI work. With out it the inheritance graph looks
like this (using _pyio):


io.IOBase    _pyio.IOBase
    |              |
io.FileIO       MyMixin
    |              |
     \            /
      \          /
       \        /
         MyClass

If you call MyClass.flush() with this hierarchy then it will propagate
to io.IOBase. Since io.IOBase doesn't call super().flush() in its flush
implementation (because it has no super class), flush propagation would
stop and MyMixin.flush wouldn't be called.

There are other ways you could solve this, of course, like getting
io.IOBase to call super().flush and ignore any errors that it gets.

But it seems like this is the right way to fix this problem anyway - as
a user, I would expect isinstance(FileIO(...), IOBase) but that is not
currently the case with _pyio.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5700>
_______________________________________


More information about the Python-bugs-list mailing list