STINNER Victor added the comment: > ITSM it's not the TextIOWrapper but the detect_encoding fails and throws an > error.
Oh, right. But TextIOWrapper can fail for differen reasons. For example, CTRL+c may send KeyboardInterrupt. Try for example: with unittest.mock.patch.object(tokenize, '_builtin_open') as mock_open: mock_file = mock_open.return_value mock_file.tell.side_effect = OSError mock_file.readline.return_value = b'' tokenize.open(fn) This example raises an OSError in TextIOWrapper on file.tell(), and file.close() is not called. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23840> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com