# HG changeset patch # User Martin Geisler # Date 1290446158 -3600 # Node ID 3da456d0c8852d448064c4cbb1fdb234e1b406b9 # Parent 8ea51e9e7031da9bcf0cea6945b78d704131a643 code style: prefer 'is' and 'is not' tests with singletons diff -r 8ea51e9e7031 -r 3da456d0c885 contrib/check-code.py --- a/contrib/check-code.py Mon Nov 22 17:57:11 2010 +0100 +++ b/contrib/check-code.py Mon Nov 22 18:15:58 2010 +0100 @@ -150,6 +150,8 @@ (r'ui\.(status|progress|write|note|warn)\([\'\"]x', "warning: unwrapped ui message"), (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"), + (r' [=!]=\s+(True|False|None)', + "comparison with singleton, use 'is' or 'is not' instead"), ] pyfilters = [ diff -r 8ea51e9e7031 -r 3da456d0c885 hgext/bookmarks.py --- a/hgext/bookmarks.py Mon Nov 22 17:57:11 2010 +0100 +++ b/hgext/bookmarks.py Mon Nov 22 18:15:58 2010 +0100 @@ -137,7 +137,7 @@ write(repo) return - if mark != None: + if mark is not None: if "\n" in mark: raise util.Abort(_("bookmark name cannot contain newlines")) mark = mark.strip() diff -r 8ea51e9e7031 -r 3da456d0c885 hgext/hgk.py --- a/hgext/hgk.py Mon Nov 22 17:57:11 2010 +0100 +++ b/hgext/hgk.py Mon Nov 22 18:15:58 2010 +0100 @@ -181,14 +181,14 @@ if i + x >= count: l[chunk - x:] = [0] * (chunk - x) break - if full != None: + if full is not None: l[x] = repo[i + x] l[x].changeset() # force reading else: l[x] = 1 for x in xrange(chunk - 1, -1, -1): if l[x] != 0: - yield (i + x, full != None and l[x] or None) + yield (i + x, full is not None and l[x] or None) if i == 0: break diff -r 8ea51e9e7031 -r 3da456d0c885 hgext/mq.py --- a/hgext/mq.py Mon Nov 22 17:57:11 2010 +0100 +++ b/hgext/mq.py Mon Nov 22 18:15:58 2010 +0100 @@ -1523,7 +1523,7 @@ l = line.rstrip() l = l[10:].split(' ') qpp = [bin(x) for x in l] - elif datastart != None: + elif datastart is not None: l = line.rstrip() n, name = l.split(':', 1) if n: diff -r 8ea51e9e7031 -r 3da456d0c885 hgext/transplant.py --- a/hgext/transplant.py Mon Nov 22 17:57:11 2010 +0100 +++ b/hgext/transplant.py Mon Nov 22 18:15:58 2010 +0100 @@ -401,7 +401,7 @@ def hasnode(repo, node): try: - return repo.changelog.rev(node) != None + return repo.changelog.rev(node) is not None except error.RevlogError: return False diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/config.py --- a/mercurial/config.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/config.py Mon Nov 22 18:15:58 2010 +0100 @@ -130,7 +130,7 @@ name = m.group(1) if sections and section not in sections: continue - if self.get(section, name) != None: + if self.get(section, name) is not None: del self._data[section][name] continue diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/context.py --- a/mercurial/context.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/context.py Mon Nov 22 18:15:58 2010 +0100 @@ -179,7 +179,7 @@ """ # deal with workingctxs n2 = c2._node - if n2 == None: + if n2 is None: n2 = c2._parents[0]._node n = self._repo.changelog.ancestor(self._node, n2) return changectx(self._repo, n) diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/manifest.py --- a/mercurial/manifest.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/manifest.py Mon Nov 22 18:15:58 2010 +0100 @@ -171,19 +171,19 @@ raise AssertionError( _("failed to remove %s from manifest") % f) l = "" - if dstart != None and dstart <= start and dend >= start: + if dstart is not None and dstart <= start and dend >= start: if dend < end: dend = end if l: dline.append(l) else: - if dstart != None: + if dstart is not None: delta.append([dstart, dend, "".join(dline)]) dstart = start dend = end dline = [l] - if dstart != None: + if dstart is not None: delta.append([dstart, dend, "".join(dline)]) # apply the delta to the addlist, and get a delta for addrevision cachedelta = (self.rev(p1), addlistdelta(addlist, delta)) diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/revlog.py --- a/mercurial/revlog.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/revlog.py Mon Nov 22 18:15:58 2010 +0100 @@ -212,7 +212,7 @@ return None self.mapfind_count += 1 last = self.l - 1 - while self.index[last] != None: + while self.index[last] is not None: if last == 0: self.all = 1 self.allmap = 1 diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/revset.py --- a/mercurial/revset.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/revset.py Mon Nov 22 18:15:58 2010 +0100 @@ -715,7 +715,7 @@ } def optimize(x, small): - if x == None: + if x is None: return 0, x smallbonus = 1 diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/ui.py --- a/mercurial/ui.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/ui.py Mon Nov 22 18:15:58 2010 +0100 @@ -589,7 +589,7 @@ termination. ''' - if pos == None or not self.debugflag: + if pos is None or not self.debugflag: return if unit: diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/util.py --- a/mercurial/util.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/util.py Mon Nov 22 18:15:58 2010 +0100 @@ -1054,7 +1054,7 @@ # NOTE: unixtime = localunixtime + offset offset, date = timezone(string), string - if offset != None: + if offset is not None: date = " ".join(string.split()[:-1]) # add missing elements from defaults diff -r 8ea51e9e7031 -r 3da456d0c885 mercurial/verify.py --- a/mercurial/verify.py Mon Nov 22 17:57:11 2010 +0100 +++ b/mercurial/verify.py Mon Nov 22 18:15:58 2010 +0100 @@ -34,7 +34,7 @@ raise util.Abort(_("cannot verify bundle or remote repos")) def err(linkrev, msg, filename=None): - if linkrev != None: + if linkrev is not None: badrevs.add(linkrev) else: linkrev = '?' diff -r 8ea51e9e7031 -r 3da456d0c885 tests/run-tests.py --- a/tests/run-tests.py Mon Nov 22 17:57:11 2010 +0100 +++ b/tests/run-tests.py Mon Nov 22 18:15:58 2010 +0100 @@ -594,7 +594,7 @@ tochild.close() output = fromchild.read() ret = fromchild.close() - if ret == None: + if ret is None: ret = 0 else: proc = Popen4(cmd) @@ -714,7 +714,7 @@ # If we're not in --debug mode and reference output file exists, # check test output against it. if options.debug: - refout = None # to match out == None + refout = None # to match "out is None" elif os.path.exists(ref): f = open(ref, "r") refout = splitnewlines(f.read())