Commit 3469f9b5 authored by Kai Willadsen's avatar Kai Willadsen

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.
parent d70e76e5
......@@ -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)
......
......@@ -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]
#
......
......@@ -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():
......
......@@ -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=()):
......
......@@ -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:
......
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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) )
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment