Mercurial > hg
changeset 13031:3da456d0c885
code style: prefer 'is' and 'is not' tests with singletons
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Mon, 22 Nov 2010 18:15:58 +0100 |
parents | 8ea51e9e7031 |
children | e41e2b79883d |
files | contrib/check-code.py hgext/bookmarks.py hgext/hgk.py hgext/mq.py hgext/transplant.py mercurial/config.py mercurial/context.py mercurial/manifest.py mercurial/revlog.py mercurial/revset.py mercurial/ui.py mercurial/util.py mercurial/verify.py tests/run-tests.py |
diffstat | 14 files changed, 19 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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 = [
--- 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()
--- 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
--- 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:
--- 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
--- 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
--- 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)
--- 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))
--- 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
--- 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
--- 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:
--- 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
--- 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 = '?'
--- 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())