Eryk Sun <eryk...@gmail.com> added the comment: This behavior is inherited from BaseException:
https://docs.python.org/3/library/exceptions.html#BaseException >>> str(BaseException()) '' >>> str(BaseException('spam')) 'spam' >>> str(BaseException('spam', 'eggs')) "('spam', 'eggs')" Python 2 OSError special cases 2-3 arguments: >>> str(OSError(*'123')) "[Errno 1] 2: '3'" >>> str(OSError(*'1234')) "('1', '2', '3', '4')" Python 3 OSError special cases 2-5 arguments (adding winerror and filename2): >>> str(OSError(*'12345')) "[Errno 1] 2: '3' -> '5'" >>> str(OSError(*'123456')) "('1', '2', '3', '4', '5', '6')" The base behavior is implemented by BaseException_str in Objects/exceptions.c: static PyObject * BaseException_str(PyBaseExceptionObject *self) { switch (PyTuple_GET_SIZE(self->args)) { case 0: return PyUnicode_FromString(""); case 1: return PyObject_Str(PyTuple_GET_ITEM(self->args, 0)); default: return PyObject_Str(self->args); } } ---------- nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33653> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com