New submission from Oren Milman:
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.
----------
components: IO
messages: 302039
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: ResourceWarning in Python/traceback.c in case of a bad io.TextIOWrapper
type: resource usage
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue31444>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com