diff -r a8e74448678c Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Tue Aug 09 15:07:06 2016 +0100 +++ b/Objects/bytearrayobject.c Wed Aug 10 03:38:48 2016 +0900 @@ -790,33 +790,33 @@ /* If it's not unicode, there can't be encoding or errors */ if (encoding != NULL || errors != NULL) { PyErr_SetString(PyExc_TypeError, "encoding or errors without a string argument"); return -1; } /* Is it an int? */ - count = PyNumber_AsSsize_t(arg, PyExc_OverflowError); - if (count == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) + if (PyIndex_Check(arg)) { + count = PyNumber_AsSsize_t(arg, PyExc_OverflowError); + if (count == -1 && PyErr_Occurred()) { return -1; - PyErr_Clear(); - } - else if (count < 0) { - PyErr_SetString(PyExc_ValueError, "negative count"); - return -1; - } - else { - if (count > 0) { - if (PyByteArray_Resize((PyObject *)self, count)) - return -1; - memset(PyByteArray_AS_STRING(self), 0, count); } - return 0; + if (count < 0) { + PyErr_SetString(PyExc_ValueError, "negative count"); + return -1; + } + else { + if (count > 0) { + if (PyByteArray_Resize((PyObject *)self, count)) + return -1; + memset(PyByteArray_AS_STRING(self), 0, count); + } + return 0; + } } /* Use the buffer API */ if (PyObject_CheckBuffer(arg)) { Py_ssize_t size; Py_buffer view; if (PyObject_GetBuffer(arg, &view, PyBUF_FULL_RO) < 0) return -1; diff -r a8e74448678c Objects/bytesobject.c --- a/Objects/bytesobject.c Tue Aug 09 15:07:06 2016 +0100 +++ b/Objects/bytesobject.c Wed Aug 10 03:38:48 2016 +0900 @@ -2558,31 +2558,31 @@ return NULL; if (PyUnicode_Check(x)) { PyErr_SetString(PyExc_TypeError, "string argument without an encoding"); return NULL; } /* Is it an integer? */ - size = PyNumber_AsSsize_t(x, PyExc_OverflowError); - if (size == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) + if (PyIndex_Check(x)) { + size = PyNumber_AsSsize_t(x, PyExc_OverflowError); + if (size == -1 && PyErr_Occurred()) { return NULL; - PyErr_Clear(); - } - else if (size < 0) { - PyErr_SetString(PyExc_ValueError, "negative count"); - return NULL; - } - else { - new = _PyBytes_FromSize(size, 1); - if (new == NULL) + } + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative count"); return NULL; - return new; + } + else { + new = _PyBytes_FromSize(size, 1); + if (new == NULL) + return NULL; + return new; + } } return PyBytes_FromObject(x); } static PyObject* _PyBytes_FromBuffer(PyObject *x) {