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. |