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:
parent
01663ecd99
commit
d3cd5a4239
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue