[Python-ideas] Add __nonzero__ to threading.Event

Floris Bruynooghe floris.bruynooghe at gmail.com
Sun May 10 19:03:22 CEST 2009


Hi

I was wondering why threading.Event hasn't got the __nonzero__ special
attribute?  I think it would allow for code to be more pythonic if you
could just do "if e: ..." instead of "if e.isSet(): ..."
(or "if e.is_set(): ..." in 2.6+).

The patch is trivial:

Index: Lib/threading.py
===================================================================
--- Lib/threading.py    (revision 72551)
+++ Lib/threading.py    (working copy)
@@ -371,6 +371,9 @@

     is_set = isSet

+    def __nonzero__(self):
+        return self.__flag
+
     def set(self):
         self.__cond.acquire()
         try:


Is it worth submitting this to the tracker or is there some reason why
this is a bad idea that I've missed?

Regards
Floris

-- 
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org



More information about the Python-ideas mailing list