# HG changeset patch # User Martin Geisler # Date 1242773566 -7200 # Node ID f9a80054dd3c4647585a6ac5475cd60a9555d6d0 # Parent f78eadbb57694afe2678d3709816088b6168fac1 use 'x is None' instead of 'x == None' The built-in None object is a singleton and it is therefore safe to compare memory addresses with is. It is also faster, how much depends on the object being compared. For a simple type like str I get: | s = "foo" | s = None ----------+-----------+---------- s == None | 0.25 usec | 0.21 usec s is None | 0.17 usec | 0.17 usec diff -r f78eadbb5769 -r f9a80054dd3c contrib/hgdiff --- a/contrib/hgdiff Wed May 20 00:43:23 2009 +0200 +++ b/contrib/hgdiff Wed May 20 00:52:46 2009 +0200 @@ -37,13 +37,13 @@ names[os.path.join(l, x)] = (st.st_dev, st.st_ino) def diff_files(file1, file2): - if file1 == None: + if file1 is None: b = file(file2).read().splitlines(1) l1 = "--- %s\n" % (file2) l2 = "+++ %s\n" % (file2) l3 = "@@ -0,0 +1,%d @@\n" % len(b) l = [l1, l2, l3] + ["+" + e for e in b] - elif file2 == None: + elif file2 is None: a = file(file1).read().splitlines(1) l1 = "--- %s\n" % (file1) l2 = "+++ %s\n" % (file1) diff -r f78eadbb5769 -r f9a80054dd3c hgext/bookmarks.py --- a/hgext/bookmarks.py Wed May 20 00:43:23 2009 +0200 +++ b/hgext/bookmarks.py Wed May 20 00:52:46 2009 +0200 @@ -143,7 +143,7 @@ return if delete: - if mark == None: + if mark is None: raise util.Abort(_("bookmark name required")) if mark not in marks: raise util.Abort(_("a bookmark of this name does not exist")) @@ -171,7 +171,7 @@ write(repo, marks) return - if mark == None: + if mark is None: if rev: raise util.Abort(_("bookmark name required")) if len(marks) == 0: @@ -243,7 +243,7 @@ """Add a revision to the repository and move the bookmark""" node = super(bookmark_repo, self).commit(*k, **kw) - if node == None: + if node is None: return None parents = repo.changelog.parents(node) if parents[1] == nullid: diff -r f78eadbb5769 -r f9a80054dd3c hgext/mq.py --- a/hgext/mq.py Wed May 20 00:43:23 2009 +0200 +++ b/hgext/mq.py Wed May 20 00:52:46 2009 +0200 @@ -430,7 +430,7 @@ if ret: raise util.Abort(_("update returned %d") % ret) n = repo.commit(None, ctx.description(), ctx.user(), force=1) - if n == None: + if n is None: raise util.Abort(_("repo commit failed")) try: ph = mergeq.readheaders(patch) @@ -603,7 +603,7 @@ n = repo.commit(files, message, ph.user, ph.date, match=match, force=True) - if n == None: + if n is None: raise util.Abort(_("repo commit failed")) if update_status: @@ -767,7 +767,7 @@ msg = msg() commitmsg = msg and msg or ("[mq]: %s" % patchfn) n = repo.commit(commitfiles, commitmsg, user, date, match=match, force=True) - if n == None: + if n is None: raise util.Abort(_("repo commit failed")) try: self.full_series[insert:insert] = [patchfn] @@ -860,7 +860,7 @@ return self.series[0] return None - if patch == None: + if patch is None: return None if patch in self.series: return patch @@ -1422,7 +1422,7 @@ applied.append(se) else: series.append(file_) - if datastart == None: + if datastart is None: self.ui.warn(_("No saved patch data found\n")) return 1 self.ui.warn(_("restoring status: %s\n") % lines[0]) @@ -1486,7 +1486,7 @@ if len(self.applied) > 0: p = self.applied[-1].name end = self.find_series(p) - if end == None: + if end is None: return len(self.full_series) return end + 1 return 0 @@ -2090,7 +2090,7 @@ m = namere.match(f) if m: index = int(m.group(1)) - if maxindex == None or index > maxindex: + if maxindex is None or index > maxindex: maxindex = index maxname = f if maxname: diff -r f78eadbb5769 -r f9a80054dd3c mercurial/archival.py --- a/mercurial/archival.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/archival.py Wed May 20 00:52:46 2009 +0200 @@ -44,7 +44,7 @@ timestamp = None if 'timestamp' in kw: timestamp = kw.pop('timestamp') - if timestamp == None: + if timestamp is None: self.timestamp = time.time() else: self.timestamp = timestamp diff -r f78eadbb5769 -r f9a80054dd3c mercurial/context.py --- a/mercurial/context.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/context.py Wed May 20 00:52:46 2009 +0200 @@ -444,7 +444,7 @@ # prime the ancestor cache for the working directory for c in (self, fc2): - if c._filerev == None: + if c._filerev is None: pl = [(n.path(), n.filenode()) for n in c.parents()] acache[(c._path, None)] = pl diff -r f78eadbb5769 -r f9a80054dd3c mercurial/copies.py --- a/mercurial/copies.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/copies.py Wed May 20 00:52:46 2009 +0200 @@ -106,7 +106,7 @@ return {}, {} # avoid silly behavior for parent -> working dir - if c2.node() == None and c1.node() == repo.dirstate.parents()[0]: + if c2.node() is None and c1.node() == repo.dirstate.parents()[0]: return repo.dirstate.copies(), {} limit = _findlimit(repo, c1.rev(), c2.rev()) diff -r f78eadbb5769 -r f9a80054dd3c mercurial/localrepo.py --- a/mercurial/localrepo.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/localrepo.py Wed May 20 00:52:46 2009 +0200 @@ -107,7 +107,7 @@ return dirstate.dirstate(self.opener, self.ui, self.root) def __getitem__(self, changeid): - if changeid == None: + if changeid is None: return context.workingctx(self) return context.changectx(self, changeid) @@ -1209,7 +1209,7 @@ fetch = set() seen = set() seenbranch = set() - if base == None: + if base is None: base = {} if not heads: @@ -1341,7 +1341,7 @@ or ancestors of these heads, and return a second element which contains all remote heads which get new children. """ - if base == None: + if base is None: base = {} self.findincoming(remote, base, heads, force=force) diff -r f78eadbb5769 -r f9a80054dd3c mercurial/patch.py --- a/mercurial/patch.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/patch.py Wed May 20 00:52:46 2009 +0200 @@ -452,11 +452,11 @@ if not m: raise PatchError(_("bad hunk #%d") % self.number) self.starta, foo, self.lena, self.startb, foo2, self.lenb = m.groups() - if self.lena == None: + if self.lena is None: self.lena = 1 else: self.lena = int(self.lena) - if self.lenb == None: + if self.lenb is None: self.lenb = 1 else: self.lenb = int(self.lenb) @@ -479,7 +479,7 @@ raise PatchError(_("bad hunk #%d") % self.number) foo, self.starta, foo2, aend, foo3 = m.groups() self.starta = int(self.starta) - if aend == None: + if aend is None: aend = self.starta self.lena = int(aend) - self.starta if self.starta: @@ -511,7 +511,7 @@ raise PatchError(_("bad hunk #%d") % self.number) foo, self.startb, foo2, bend, foo3 = m.groups() self.startb = int(self.startb) - if bend == None: + if bend is None: bend = self.startb self.lenb = int(bend) - self.startb if self.startb: @@ -872,7 +872,7 @@ if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or ((context is not False) and x.startswith('***************')))): try: - if context == None and x.startswith('***************'): + if context is None and x.startswith('***************'): context = True gpatch = changed.get(bfile) create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD' diff -r f78eadbb5769 -r f9a80054dd3c mercurial/revlog.py --- a/mercurial/revlog.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/revlog.py Wed May 20 00:52:46 2009 +0200 @@ -175,7 +175,7 @@ if lend > len(self.index) - i: lend = len(self.index) - i for x in xrange(lend): - if self.index[i + x] == None: + if self.index[i + x] is None: b = data[off : off + self.s] self.index[i + x] = b n = b[ngshaoffset:ngshaoffset + 20] @@ -231,7 +231,7 @@ if self.all: return all = False - if i == None: + if i is None: blockstart = 0 blocksize = (65536 / self.s) * self.s end = self.datasize @@ -279,7 +279,7 @@ self.p = parser def load(self, key): n = self.p.findnode(key) - if n == None: + if n is None: raise KeyError(key) def __contains__(self, key): if key in self.p.map: @@ -1019,7 +1019,7 @@ return trinfo = tr.find(self.indexfile) - if trinfo == None: + if trinfo is None: raise RevlogError(_("%s not found in the transaction") % self.indexfile) diff -r f78eadbb5769 -r f9a80054dd3c mercurial/ui.py --- a/mercurial/ui.py Wed May 20 00:43:23 2009 +0200 +++ b/mercurial/ui.py Wed May 20 00:52:46 2009 +0200 @@ -129,7 +129,7 @@ def configbool(self, section, name, default=False, untrusted=False): v = self.config(section, name, None, untrusted) - if v == None: + if v is None: return default if v.lower() not in _booleans: raise error.ConfigError(_("%s.%s not a boolean ('%s')")