Commits

Armin Rigo committed 45310cd

Test and fix

Comments (0)

Files changed (2)

lib_pypy/greenlet.py

     def __switch(target, methodname, *args):
         current = getcurrent()
         #
-        while not target:
+        while not (target.__main or _continulet.is_pending(target)):
+            # inlined __nonzero__ ^^^ in case it's overridden
             if not target.__started:
                 if methodname == 'switch':
                     greenlet_func = _greenlet_start

pypy/module/test_lib_pypy/test_greenlet.py

         assert g.gr_frame.f_code.co_name == 'f2'
         g.switch()
         assert g.gr_frame is None
+
+    def test_override_nonzero(self):
+        from greenlet import greenlet
+        class G(greenlet):
+            def __nonzero__(self):
+                raise ValueError
+        g = G(lambda: 42)
+        x = g.switch()
+        assert x == 42