changeset 22225:baecf4e1b7d0

ancestors: add a __nonzero__ method This allows using the object in a conditional the same way we can use list.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 15 Aug 2014 15:57:50 -0700
parents f713de1d3916
children 827bce9e24fb
files mercurial/ancestor.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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.