diff -r 1002a1bdc5b1 Objects/bytesobject.c --- a/Objects/bytesobject.c Sun Aug 07 10:19:20 2016 -0700 +++ b/Objects/bytesobject.c Mon Aug 08 04:15:08 2016 +0900 @@ -2563,21 +2563,23 @@ 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()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); // Fallback to below + } + else if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative count"); 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) - return NULL; - return new; + } + else { + new = _PyBytes_FromSize(size, 1); + if (new == NULL) + return NULL; + return new; + } } return PyBytes_FromObject(x);