Message317744
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);
}
} |
|
Date |
User |
Action |
Args |
2018-05-26 17:12:53 | eryksun | set | recipients:
+ eryksun, giampaolo.rodola, serhiy.storchaka |
2018-05-26 17:12:53 | eryksun | set | messageid: <1527354773.07.0.682650639539.issue33653@psf.upfronthosting.co.za> |
2018-05-26 17:12:53 | eryksun | link | issue33653 messages |
2018-05-26 17:12:53 | eryksun | create | |
|