--- src/templates/object.derived +++ src/templates/object.derived @@ -149,8 +149,16 @@ if (impl != null) { PyObject res = impl.__get__(this,self_type).__call__(); if (res instanceof PyInteger) - return ((PyInteger)res).getValue(); - throw Py.TypeError("__len__ should return a int"); + return ((PyInteger)res).getValue(); + if (impl instanceof PyInstance) { + throw Py.TypeError("__len__ should return a int"); + } else { + if (res instanceof PyLong) { + throw Py.OverflowError("long int too large to convert to int"); + } else { + throw Py.TypeError("an integer is required"); + } + } } return super.__len__(); }