[issue33762] Make tempfiles subclass IOBase

Terry J. Reedy report at bugs.python.org
Tue Dec 10 17:50:55 EST 2019


Terry J. Reedy <tjreedy at udel.edu> added the comment:

TemporaryFile() returns an instance of _TemporaryFileWrapper.  isinstance(TemporaryFile(), io.IOBase) is a sensible thing to do and would be True if _TemporaryFileWrapper subclassed the appropriate io base file.

The base class for IDLE's stdxxx pseudofiles does this and hence, for instance,

>>> sys.stdout
<idlelib.run.StdOutputFile object at 0x0000023BEB515F70>
>>> isinstance(sys.stdout, io.IOBase)
True

I believe that tempfile long predates io, added in 2.6.  Since the IO base classes are not 'abstract base classes' in the sense of subclassing abc.ABCMeta, the tempfile classes cannot just be registered as implementing them.  And tempfile has never been re-written to be based on io, by subclassing io base classes.

Doing so would fix this issue.  It *might* result in simpler tempfile code (but I would not be sure until it is done).  It would also address (but not automatically fix) #26175. I think SpooledTemporaryFile would likely be the hardest.  Martin and Serhiy are correct that a change would be an enhancement, not a bugfix.

----------
stage:  -> test needed
title: temp file isn't IOBase -> Make tempfiles subclass IOBase
type: behavior -> enhancement
versions:  -Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33762>
_______________________________________


More information about the Python-bugs-list mailing list