ancestors: add a __nonzero__ method
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 15 Aug 2014 15:57:50 -0700
changeset 22225 baecf4e1b7d0
parent 22224 f713de1d3916
child 22226 827bce9e24fb
ancestors: add a __nonzero__ method This allows using the object in a conditional the same way we can use list.
mercurial/ancestor.py
--- a/mercurial/ancestor.py	Fri Aug 15 15:25:12 2014 -0700
+++ b/mercurial/ancestor.py	Fri Aug 15 15:57:50 2014 -0700
@@ -246,6 +246,14 @@
         else:
             self._containsseen = set()
 
+    def __nonzero__(self):
+        """False if the set is empty, True otherwise."""
+        try:
+            iter(self).next()
+            return True
+        except StopIteration:
+            return False
+
     def __iter__(self):
         """Generate the ancestors of _initrevs in reverse topological order.