mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception.
This commit is contained in:
parent
a251fb02f4
commit
a634e23209
4 changed files with 41 additions and 18 deletions
|
@ -2593,16 +2593,20 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
if (PyIndex_Check(x)) {
|
||||
size = PyNumber_AsSsize_t(x, PyExc_OverflowError);
|
||||
if (size == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||
return NULL;
|
||||
PyErr_Clear(); /* fall through */
|
||||
}
|
||||
if (size < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
return NULL;
|
||||
else {
|
||||
if (size < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
return NULL;
|
||||
}
|
||||
new = _PyBytes_FromSize(size, 1);
|
||||
if (new == NULL)
|
||||
return NULL;
|
||||
return new;
|
||||
}
|
||||
new = _PyBytes_FromSize(size, 1);
|
||||
if (new == NULL)
|
||||
return NULL;
|
||||
return new;
|
||||
}
|
||||
|
||||
return PyBytes_FromObject(x);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue