Mercurial > public > mercurial-scm > hg-stable
diff mercurial/ancestor.py @ 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 | 64911a12dc28 |
children | 3a7d9c0c57a5 |
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.