Mercurial > public > mercurial-scm > hg
diff mercurial/smartset.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 6309128ff61f |
children | 687b865b95ad |
line wrap: on
line diff
--- a/mercurial/smartset.py Sat Oct 05 10:29:34 2019 -0400 +++ b/mercurial/smartset.py Sun Oct 06 09:45:02 2019 -0400 @@ -13,15 +13,14 @@ pycompat, util, ) -from .utils import ( - stringutil, -) +from .utils import stringutil + def _typename(o): return pycompat.sysbytes(type(o).__name__).lstrip('_') + class abstractsmartset(object): - def __nonzero__(self): """True if the smartset is not empty""" raise NotImplementedError() @@ -125,8 +124,9 @@ This is part of the mandatory API for smartset.""" c = other.__contains__ - return self.filter(lambda r: not c(r), condrepr=('<not %r>', other), - cache=False) + return self.filter( + lambda r: not c(r), condrepr=('<not %r>', other), cache=False + ) def filter(self, condition, condrepr=None, cache=True): """Returns this smartset filtered by condition as a new smartset. @@ -163,6 +163,7 @@ ys.append(y) return baseset(ys, datarepr=('slice=%d:%d %r', start, stop, self)) + class baseset(abstractsmartset): """Basic data structure that represents a revset and contains the basic operation that it should be able to perform. @@ -222,6 +223,7 @@ >>> rs._istopo True """ + def __init__(self, data=(), datarepr=None, istopo=False): """ datarepr: a tuple of (format, obj, ...), a function or an object that @@ -342,10 +344,15 @@ def _fastsetop(self, other, op): # try to use native set operations as fast paths - if (type(other) is baseset and r'_set' in other.__dict__ and r'_set' in - self.__dict__ and self._ascending is not None): - s = baseset(data=getattr(self._set, op)(other._set), - istopo=self._istopo) + if ( + type(other) is baseset + and r'_set' in other.__dict__ + and r'_set' in self.__dict__ + and self._ascending is not None + ): + s = baseset( + data=getattr(self._set, op)(other._set), istopo=self._istopo + ) s._ascending = self._ascending else: s = getattr(super(baseset, self), op)(other) @@ -383,11 +390,13 @@ s = pycompat.byterepr(l) return '<%s%s %s>' % (_typename(self), d, s) + class filteredset(abstractsmartset): """Duck type for baseset class which iterates lazily over the revisions in the subset and contains a function which tests for membership in the revset """ + def __init__(self, subset, condition=lambda x: True, condrepr=None): """ condition: a function that decide whether a revision in the subset @@ -427,10 +436,12 @@ def __nonzero__(self): fast = None - candidates = [self.fastasc if self.isascending() else None, - self.fastdesc if self.isdescending() else None, - self.fastasc, - self.fastdesc] + candidates = [ + self.fastasc if self.isascending() else None, + self.fastdesc if self.isdescending() else None, + self.fastasc, + self.fastdesc, + ] for candidate in candidates: if candidate is not None: fast = candidate @@ -484,7 +495,7 @@ if it is not None: for x in it(): return x - return None #empty case + return None # empty case else: x = None for x in self: @@ -499,6 +510,7 @@ xs.append(s) return '<%s %s>' % (_typename(self), ', '.join(xs)) + def _iterordered(ascending, iter1, iter2): """produce an ordered iteration from two iterators with the same order @@ -535,6 +547,7 @@ for val in it: yield val + class addset(abstractsmartset): """Represent the addition of two sets @@ -606,6 +619,7 @@ >>> [x for x in rs] [5, 4, 3, 2, 0] """ + def __init__(self, revs1, revs2, ascending=None): self._r1 = revs1 self._r2 = revs2 @@ -641,6 +655,7 @@ if self._ascending is None: if self._genlist: return iter(self._genlist) + def arbitraryordergen(): for r in self._r1: yield r @@ -648,6 +663,7 @@ for r in self._r2: if not inr1(r): yield r + return arbitraryordergen() # try to use our own fast iterator if it exists self._trysetasclist() @@ -747,6 +763,7 @@ d = {None: '', False: '-', True: '+'}[self._ascending] return '<%s%s %r, %r>' % (_typename(self), d, self._r1, self._r2) + class generatorset(abstractsmartset): """Wrap a generator for lazy iteration @@ -760,6 +777,7 @@ >>> xs.last() # cached 4 """ + def __new__(cls, gen, iterasc=None): if iterasc is None: typ = cls @@ -830,7 +848,8 @@ # iteration. genlist = self._genlist nextgen = self._consumegen() - _len, _next = len, next # cache global lookup + _len, _next = len, next # cache global lookup + def gen(): i = 0 while True: @@ -842,6 +861,7 @@ except StopIteration: return i += 1 + return gen() def _consumegen(self): @@ -911,6 +931,7 @@ d = {False: '-', True: '+'}[self._ascending] return '<%s%s>' % (_typename(self), d) + class _generatorsetasc(generatorset): """Special case of generatorset optimized for ascending generators.""" @@ -930,6 +951,7 @@ self._cache[x] = False return False + class _generatorsetdesc(generatorset): """Special case of generatorset optimized for descending generators.""" @@ -949,6 +971,7 @@ self._cache[x] = False return False + def spanset(repo, start=0, end=None): """Create a spanset that represents a range of repository revisions @@ -964,6 +987,7 @@ start, end = end + 1, start + 1 return _spanset(start, end, ascending, repo.changelog.filteredrevs) + class _spanset(abstractsmartset): """Duck type for baseset class which represents a range of revisions and can work lazily and without having all the range in memory @@ -974,6 +998,7 @@ - revision filtered with this repoview will be skipped. """ + def __init__(self, start, end, ascending, hiddenrevs): self._start = start self._end = end @@ -1018,8 +1043,9 @@ def __contains__(self, rev): hidden = self._hiddenrevs - return ((self._start <= rev < self._end) - and not (hidden and rev in hidden)) + return (self._start <= rev < self._end) and not ( + hidden and rev in hidden + ) def __nonzero__(self): for r in self: @@ -1081,6 +1107,7 @@ d = {False: '-', True: '+'}[self._ascending] return '<%s%s %d:%d>' % (_typename(self), d, self._start, self._end) + class fullreposet(_spanset): """a set containing all revisions in the repo @@ -1089,8 +1116,9 @@ """ def __init__(self, repo): - super(fullreposet, self).__init__(0, len(repo), True, - repo.changelog.filteredrevs) + super(fullreposet, self).__init__( + 0, len(repo), True, repo.changelog.filteredrevs + ) def __and__(self, other): """As self contains the whole repo, all of the other set should also be