Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 25146:f542a2c89b60
generatorset: use 'next()' to simplify the code
The 'next()' built-in accept a default value. This remove the needs to check if
self non-empty before returning a value.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Sun, 17 May 2015 18:06:09 -0700 |
parents | 3553163bb736 |
children | 3f0744eeaeaf |
comparison
equal
deleted
inserted
replaced
25145:3553163bb736 | 25146:f542a2c89b60 |
---|---|
3320 if it is None: | 3320 if it is None: |
3321 # we need to consume all and try again | 3321 # we need to consume all and try again |
3322 for x in self._consumegen(): | 3322 for x in self._consumegen(): |
3323 pass | 3323 pass |
3324 return self.first() | 3324 return self.first() |
3325 if self: | 3325 return next(it(), None) |
3326 return it().next() | |
3327 return None | |
3328 | 3326 |
3329 def last(self): | 3327 def last(self): |
3330 if self._ascending: | 3328 if self._ascending: |
3331 it = self.fastdesc | 3329 it = self.fastdesc |
3332 else: | 3330 else: |
3334 if it is None: | 3332 if it is None: |
3335 # we need to consume all and try again | 3333 # we need to consume all and try again |
3336 for x in self._consumegen(): | 3334 for x in self._consumegen(): |
3337 pass | 3335 pass |
3338 return self.first() | 3336 return self.first() |
3339 if self: | 3337 return next(it(), None) |
3340 return it().next() | |
3341 return None | |
3342 | 3338 |
3343 def __repr__(self): | 3339 def __repr__(self): |
3344 d = {False: '-', True: '+'}[self._ascending] | 3340 d = {False: '-', True: '+'}[self._ascending] |
3345 return '<%s%s>' % (type(self).__name__, d) | 3341 return '<%s%s>' % (type(self).__name__, d) |
3346 | 3342 |