Commit 7c751f48 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fall back on __len__ if __nonzero__ doesnt exist

parent 417e1c5f
......@@ -1689,6 +1689,8 @@ extern "C" bool nonzero(Box* obj) {
// go through descriptor logic
Box* func = getclsattr_internal(obj, "__nonzero__", NULL);
if (!func)
func = getclsattr_internal(obj, "__len__", NULL);
if (func == NULL) {
ASSERT(isUserDefined(obj->cls) || obj->cls == classobj_cls, "%s.__nonzero__",
......@@ -1697,6 +1699,7 @@ extern "C" bool nonzero(Box* obj) {
}
Box* r = runtimeCall0(func, ArgPassSpec(0));
// I believe this behavior is handled by the slot wrappers in CPython:
if (r->cls == bool_cls) {
BoxedBool* b = static_cast<BoxedBool*>(r);
bool rtn = b->n;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment