STINNER Victor added the comment: > 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().
I consider that _Py_DisplaySourceLine() is right to expect that io.TextIOWrapper() creates a stream object. If the TextIOWrapper creation fails, it calls binary.close() to prevent a resource warning. Here your function doesn't fail but returns None which is really not expected. > def _bad_TextIOWrapper(*args): return None > io.TextIOWrapper = _bad_TextIOWrapper I don't see why Python should support such strange TextIOWrapper type. I simply suggest to close the issue as WONTFIX. ---------- nosy: +haypo, pitrou, serhiy.storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue31444> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com