# HG changeset patch # User Pierre-Yves David # Date 2014-08-15 22:57:50 # Node ID baecf4e1b7d02f62b368515bf07f5239b10ab9b9 # Parent f713de1d391664614add55577d71e9b52ff328a7 ancestors: add a __nonzero__ method This allows using the object in a conditional the same way we can use list. diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py --- a/mercurial/ancestor.py +++ b/mercurial/ancestor.py @@ -246,6 +246,14 @@ class lazyancestors(object): 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.