[meld] Replace equality comparisons with identity comparisons to None
- From: Kai Willadsen <kaiw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [meld] Replace equality comparisons with identity comparisons to None
- Date: Sun, 13 Sep 2009 09:45:38 +0000 (UTC)
commit 3469f9b5249dc0a038e9c5509853d7dc1352ad0a
Author: Kai Willadsen <kai willadsen gmail com>
Date: Mon Aug 17 10:33:07 2009 +1000
Replace equality comparisons with identity comparisons to None
As None is a singleton, identity comparisons are safer (classes can
provide unusual equality overrides) and apparently faster.
meld/diffutil.py | 2 +-
meld/dirdiff.py | 25 +++++++++++++------------
meld/filediff.py | 2 +-
meld/misc.py | 2 +-
meld/ui/findbar.py | 4 ++--
meld/undo.py | 12 ++++++------
meld/util/prefs.py | 4 ++--
meld/vc/bzr.py | 4 ++--
meld/vc/cvs.py | 4 ++--
meld/vc/mercurial.py | 4 ++--
meld/vcview.py | 4 ++--
11 files changed, 34 insertions(+), 33 deletions(-)
---
diff --git a/meld/diffutil.py b/meld/diffutil.py
index 08b8470..8e45a7b 100644
--- a/meld/diffutil.py
+++ b/meld/diffutil.py
@@ -257,7 +257,7 @@ class Differ(object):
for i in range(self.num_sequences - 1):
matcher = self._matcher(None, sequences[1], sequences[i*2])
work = matcher.initialise()
- while work.next() == None:
+ while work.next() is None:
yield None
self.diffs[i] = matcher.get_difference_opcodes()
self._update_merge_cache(sequences)
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 092e8ad..e078d8d 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -286,7 +286,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
except re.error:
misc.run_dialog( _("Error converting pattern '%s' to regular expression") % f.value, self )
else:
- func = lambda x, r=cregex : r.match(x) == None
+ func = lambda x, r=cregex : r.match(x) is None
self.name_filters_available.append( TypeFilter(f.name, f.active, func) )
self.name_filters = [f for f in self.name_filters_available if f.active]
@@ -414,7 +414,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
for i in items:
ci = canonicalize(i)
try:
- assert self.items[ ci ][pane] == None
+ assert self.items[ci][pane] is None
except KeyError:
self.items[ ci ] = self.default[:]
self.items[ ci ][pane] = i
@@ -517,7 +517,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
"""Launch comparisons on all selected elements.
"""
pane = self._get_focused_pane()
- if pane != None:
+ if pane is not None:
selected = self._get_selected_paths(pane)
get_iter = self.model.get_iter
for s in selected:
@@ -526,16 +526,16 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
def copy_selected(self, direction):
assert direction in (-1,1)
src_pane = self._get_focused_pane()
- if src_pane != None:
+ if src_pane is not None:
dst_pane = src_pane + direction
assert dst_pane >= 0 and dst_pane < self.num_panes
paths = self._get_selected_paths(src_pane)
paths.reverse()
model = self.model
- for path in paths: #filter(lambda x: x.name!=None, sel):
+ for path in paths: #filter(lambda x: x.name is not None, sel):
it = model.get_iter(path)
name = model.value_path(it, src_pane)
- if name == None:
+ if name is None:
continue
src = model.value_path(it, src_pane)
dst = model.value_path(it, dst_pane)
@@ -562,7 +562,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
"""
# reverse so paths dont get changed
pane = self._get_focused_pane()
- if pane != None:
+ if pane is not None:
paths = self._get_selected_paths(pane)
paths.reverse()
for path in paths:
@@ -584,7 +584,8 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
def on_treeview_cursor_changed(self, *args):
pane = self._get_focused_pane()
- if pane == None: return
+ if pane is None:
+ return
paths = self._get_selected_paths(pane)
if len(paths) > 0:
def rwx(mode):
@@ -619,7 +620,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
elif gtk.keysyms.Left == event.keyval:
if pane-1 >= 0:
tree = self.treeview[pane-1]
- if tree != None:
+ if tree is not None:
paths = self._get_selected_paths(pane)
view.get_selection().unselect_all()
tree.grab_focus()
@@ -690,7 +691,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
self.delete_selected()
def on_button_open_clicked(self, button):
pane = self._get_focused_pane()
- if pane != None:
+ if pane is not None:
m = self.model
files = [ m.value_path( m.get_iter(p), pane ) for p in self._get_selected_paths(pane) ]
self._open_files(files)
@@ -725,7 +726,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
def on_filter_hide_current_clicked(self, button):
pane = self._get_focused_pane()
- if pane != None:
+ if pane is not None:
paths = self._get_selected_paths(pane)
paths.reverse()
for p in paths:
@@ -735,7 +736,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
# Selection
#
def _get_selected_paths(self, pane):
- assert pane != None
+ assert pane is not None
return self.treeview[pane].get_selection().get_selected_rows()[1]
#
diff --git a/meld/filediff.py b/meld/filediff.py
index e194f0f..039df08 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -626,7 +626,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
panetext = [self._filter_text(p) for p in panetext]
lines = map(lambda x: x.split("\n"), panetext)
step = self.linediffer.set_sequences_iter(lines)
- while step.next() == None:
+ while step.next() is None:
yield 1
if self.num_panes > 1 and self.linediffer.sequences_identical():
diff --git a/meld/misc.py b/meld/misc.py
index 8b1dee8..a1decb8 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -50,7 +50,7 @@ def cmdout(cmd, text=None, **kwargs):
def shelljoin( command ):
def quote(s):
- return ((whitespace_re.search(s) == None) and s or ('"%s"' % s))
+ return ((whitespace_re.search(s) is None) and s or ('"%s"' % s))
return " ".join( [ quote(x) for x in command ] )
def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK, extrabuttons=()):
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index d6a324f..9730b95 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -120,13 +120,13 @@ class FindBar(gnomeglade.Component):
else:
if backwards == False:
match = pattern.search(text, insert.get_offset() + start_offset)
- if match == None and wrap:
+ if match is None and wrap:
match = pattern.search(text, 0)
else:
match = None
for m in pattern.finditer(text, 0, insert.get_offset()):
match = m
- if match == None and wrap:
+ if match is None and wrap:
for m in pattern.finditer(text, insert.get_offset()):
match = m
if match:
diff --git a/meld/undo.py b/meld/undo.py
index f4f2d11..c0dac55 100644
--- a/meld/undo.py
+++ b/meld/undo.py
@@ -72,7 +72,7 @@ class UndoSequence(gobject.GObject):
"""
if hasattr(self, "group"):
- assert self.group == None
+ assert self.group is None
if self.can_undo():
self.emit('can-undo', 0)
if self.can_redo():
@@ -99,7 +99,7 @@ class UndoSequence(gobject.GObject):
action -- A class with two callable attributes: 'undo' and 'redo'
which are called by this sequence during an undo or redo.
"""
- if self.group == None:
+ if self.group is None:
could_undo = self.can_undo()
could_redo = self.can_redo()
self.actions[self.next_redo:] = []
@@ -161,8 +161,8 @@ class UndoSequence(gobject.GObject):
Raises an AssertionError if there was not a matching call to
begin_group().
"""
- assert self.group != None
- if self.group.group != None:
+ assert self.group is not None
+ if self.group.group is not None:
self.group.end_group()
else:
group = self.group
@@ -177,8 +177,8 @@ class UndoSequence(gobject.GObject):
Raises an AssertionError if there was no a matching call to begin_group().
"""
- assert self.group != None
- if self.group.group != None:
+ assert self.group is not None
+ if self.group.group is not None:
self.group.abort_group()
else:
self.group = None
diff --git a/meld/util/prefs.py b/meld/util/prefs.py
index 8ec5443..cfb90b2 100644
--- a/meld/util/prefs.py
+++ b/meld/util/prefs.py
@@ -93,7 +93,7 @@ class GConfPreferences(object):
self._gconf.notify_add(rootkey, self._on_preference_changed)
for key, value in self._prefs.items():
gval = self._gconf.get_without_default("%s/%s" % (rootkey, key) )
- if gval != None:
+ if gval is not None:
value.current = getattr( gval, "get_%s" % value.type )()
def __getattr__(self, attr):
@@ -121,7 +121,7 @@ class GConfPreferences(object):
except KeyError: # unknown key, we don't care about it
pass
else:
- if entry.value != None: # value has changed
+ if entry.value is not None: # value has changed
newval = getattr(entry.value, "get_%s" % valuestruct.type)()
setattr( self, attr, newval)
else: # value has been deleted
diff --git a/meld/vc/bzr.py b/meld/vc/bzr.py
index e7c370d..f6de97c 100644
--- a/meld/vc/bzr.py
+++ b/meld/vc/bzr.py
@@ -101,12 +101,12 @@ class Vc(_vc.CachedVc):
bzrfiles[name] = 1
for f,path in files:
if f not in bzrfiles:
- #state = ignore_re.match(f) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
+ #state = ignore_re.match(f) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
state = _vc.STATE_NORMAL
retfiles.append( _vc.File(path, f, state, "") )
for d,path in dirs:
if d not in bzrfiles:
- #state = ignore_re.match(f) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
+ #state = ignore_re.match(f) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
state = _vc.STATE_NORMAL
retdirs.append( _vc.Dir(path, d, state) )
return retdirs, retfiles
diff --git a/meld/vc/cvs.py b/meld/vc/cvs.py
index 010fce1..4cde7be 100644
--- a/meld/vc/cvs.py
+++ b/meld/vc/cvs.py
@@ -158,11 +158,11 @@ class Vc(_vc.Vc):
for f,path in files:
if f not in cvsfiles:
- state = ignore_re.match(f) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
+ state = ignore_re.match(f) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
retfiles.append( _vc.File(path, f, state, "") )
for d,path in dirs:
if d not in cvsfiles:
- state = ignore_re.match(d) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
+ state = ignore_re.match(d) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
retdirs.append( _vc.Dir(path, d, state) )
return retdirs, retfiles
diff --git a/meld/vc/mercurial.py b/meld/vc/mercurial.py
index 1d7aa55..0879636 100644
--- a/meld/vc/mercurial.py
+++ b/meld/vc/mercurial.py
@@ -83,12 +83,12 @@ class Vc(_vc.Vc):
hgfiles[name] = 1
for f,path in files:
if f not in hgfiles:
- #state = ignore_re.match(f) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
+ #state = ignore_re.match(f) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
state = _vc.STATE_NORMAL
retfiles.append( _vc.File(path, f, state, "") )
for d,path in dirs:
if d not in hgfiles:
- #state = ignore_re.match(f) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
+ #state = ignore_re.match(f) is None and _vc.STATE_NONE or _vc.STATE_IGNORED
state = _vc.STATE_NORMAL
retdirs.append( _vc.Dir(path, d, state) )
diff --git a/meld/vcview.py b/meld/vcview.py
index 0b05afa..4ed06d5 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -393,7 +393,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
s = self.treeview.get_selection()
s.selected_foreach(gather)
# remove empty entries and remove trailing slashes
- return [ x[-1]!="/" and x or x[:-1] for x in sel if x != None ]
+ return [x[-1] != "/" and x or x[:-1] for x in sel if x is not None]
def _command_iter(self, command, files, refresh):
"""Run 'command' on 'files'. Return a tuple of the directory the
@@ -415,7 +415,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
self.consolestream.write( misc.shelljoin(command+files) + " (in %s)\n" % workdir)
readfunc = misc.read_pipe_iter(command + files, self.consolestream, workdir=workdir).next
try:
- while r == None:
+ while r is None:
r = readfunc()
self.consolestream.write(r)
yield 1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]