Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 62990) +++ Objects/typeobject.c (working copy) @@ -4574,6 +4574,9 @@ len = PyLong_AsSsize_t(res); Py_DECREF(res); if (len < 0) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + PyErr_SetString(PyExc_OverflowError, + "Length too large"); if (!PyErr_Occurred()) PyErr_SetString(PyExc_ValueError, "__len__() should return >= 0"); Index: Objects/rangeobject.c =================================================================== --- Objects/rangeobject.c (revision 62990) +++ Objects/rangeobject.c (working copy) @@ -197,6 +197,10 @@ Py_ssize_t result = -1; if (len) { result = PyLong_AsSsize_t(len); + if (result == -1 && PyErr_ExceptionMatches(PyExc_OverflowError)) + PyErr_SetString(PyExc_OverflowError, + "Length too large"); + Py_DECREF(len); } return result;