bool(x) True if x is an object without one of the magic methods you mentioned that returns False . Therefore, Ellipsis is rated True .
None with special trims in bool() and returns it False .
Details:
bool() uses the PyObject_IsTrue() API function, which in 2.7.2 looks like this:
int PyObject_IsTrue(PyObject *v) { Py_ssize_t res; if (v == Py_True) return 1; if (v == Py_False) return 0; if (v == Py_None) return 0; else if (v->ob_type->tp_as_number != NULL && v->ob_type->tp_as_number->nb_nonzero != NULL) res = (*v->ob_type->tp_as_number->nb_nonzero)(v); else if (v->ob_type->tp_as_mapping != NULL && v->ob_type->tp_as_mapping->mp_length != NULL) res = (*v->ob_type->tp_as_mapping->mp_length)(v); else if (v->ob_type->tp_as_sequence != NULL && v->ob_type->tp_as_sequence->sq_length != NULL) res = (*v->ob_type->tp_as_sequence->sq_length)(v); else return 1; return (res > 0) ? 1 : Py_SAFE_DOWNCAST(res, Py_ssize_t, int); }
source share