Message 302039 - Python tracker

Message302039

Author Oren Milman
Recipients Oren Milman
Date 2017-09-13.09:12:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1505293970.62.0.0376134228413.issue31444@psf.upfronthosting.co.za>
In-reply-to
Content
the following code causes a ResourceWarning:

import io
def _bad_TextIOWrapper(*args):
    return None
io.TextIOWrapper = _bad_TextIOWrapper
1/0


this is because _Py_DisplaySourceLine() (in Python/traceback.c) assumes that
io.TextIOWrapper() returned a stream object, and tries to call its close() 
method. in case calling close() fails, _Py_DisplaySourceLine() just calls
PyErr_Clear().


maybe _Py_DisplaySourceLine() should try to call binary.close() in such cases?

I also thought about adding a check such as:
PyObject_IsInstance(fob, (PyObject*)&PyTextIOWrapper_Type);
but I am not sure whether we should use PyTextIOWrapper_Type outside of the io
module.
History
Date User Action Args
2017-09-13 09:12:50Oren Milmansetrecipients: + Oren Milman
2017-09-13 09:12:50Oren Milmansetmessageid: <1505293970.62.0.0376134228413.issue31444@psf.upfronthosting.co.za>
2017-09-13 09:12:50Oren Milmanlinkissue31444 messages
2017-09-13 09:12:50Oren Milmancreate