Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 66056) +++ Objects/typeobject.c (working copy) @@ -4633,6 +4633,11 @@ if (res == NULL) return -1; + if (!PyLong_Check(res)) { + PyErr_SetString(PyExc_TypeError, + "__len__() should return an int"); + return -1; + } len = PyLong_AsSsize_t(res); Py_DECREF(res); if (len < 0) {