Eo: Add a boolean special method which does the same (opposite) as is_deleted().

Now you can write:

    if not my_obj:
        raise VeryBadError("My object is gone!")

and:

    if my_obj:
        my_obj.manipulate()

instead of:

    if my_obj.is_deleted()
        raise ErrorBadVery("Where did it go?")

and:

    if not my_obj.is_deleted():
        my_obj.manipulate()

But really, we should add NULL checks all over the place instead of
having the end developers checking for it.
This commit is contained in:
Kai Huuhko 2013-04-23 13:09:44 +00:00
parent 01663ecd99
commit d3cd5a4239
1 changed files with 3 additions and 0 deletions

View File

@ -291,6 +291,9 @@ cdef class Eo(object):
<unsigned long>eo_parent_get(self.obj) if self.obj != NULL else 0,
PY_REFCOUNT(self))
def __nonzero__(self):
return 1 if self.obj != NULL else 0
cdef void _set_obj(self, cEo *obj) except *:
assert self.obj == NULL, "Object must be clean"
assert obj != NULL, "Cannot set a NULL object"