kuuko pushed a commit to branch master.

commit d3cd5a4239c771b9224267eaa8f73631d214cab1
Author: Kai Huuhko <[email protected]>
Date:   Tue Apr 23 13:09:44 2013 +0000

    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.
---
 efl/eo/efl.eo.pyx | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/efl/eo/efl.eo.pyx b/efl/eo/efl.eo.pyx
index 7e311c2..6ab3f85 100644
--- a/efl/eo/efl.eo.pyx
+++ b/efl/eo/efl.eo.pyx
@@ -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"

-- 

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1

Reply via email to