[issue33653] EnvironmentError does not set errno unless strerror is set
Eryk Sun
report at bugs.python.org
Sat May 26 13:12:53 EDT 2018
Eryk Sun <eryksun at 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 <report at bugs.python.org>
<https://bugs.python.org/issue33653>
_______________________________________
More information about the Python-bugs-list
mailing list