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): ...@@ -257,7 +257,7 @@ class Differ(object):
for i in range(self.num_sequences - 1): for i in range(self.num_sequences - 1):
matcher = self._matcher(None, sequences[1], sequences[i*2]) matcher = self._matcher(None, sequences[1], sequences[i*2])
work = matcher.initialise() work = matcher.initialise()
while work.next() == None: while work.next() is None:
yield None yield None
self.diffs[i] = matcher.get_difference_opcodes() self.diffs[i] = matcher.get_difference_opcodes()
self._update_merge_cache(sequences) self._update_merge_cache(sequences)
......
...@@ -286,7 +286,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -286,7 +286,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
except re.error: except re.error:
misc.run_dialog( _("Error converting pattern '%s' to regular expression") % f.value, self ) misc.run_dialog( _("Error converting pattern '%s' to regular expression") % f.value, self )
else: 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_available.append( TypeFilter(f.name, f.active, func) )
self.name_filters = [f for f in self.name_filters_available if f.active] self.name_filters = [f for f in self.name_filters_available if f.active]
...@@ -414,7 +414,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -414,7 +414,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
for i in items: for i in items:
ci = canonicalize(i) ci = canonicalize(i)
try: try:
assert self.items[ ci ][pane] == None assert self.items[ci][pane] is None
except KeyError: except KeyError:
self.items[ ci ] = self.default[:] self.items[ ci ] = self.default[:]
self.items[ ci ][pane] = i self.items[ ci ][pane] = i
...@@ -517,7 +517,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -517,7 +517,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
"""Launch comparisons on all selected elements. """Launch comparisons on all selected elements.
""" """
pane = self._get_focused_pane() pane = self._get_focused_pane()
if pane != None: if pane is not None:
selected = self._get_selected_paths(pane) selected = self._get_selected_paths(pane)
get_iter = self.model.get_iter get_iter = self.model.get_iter
for s in selected: for s in selected:
...@@ -526,16 +526,16 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -526,16 +526,16 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
def copy_selected(self, direction): def copy_selected(self, direction):
assert direction in (-1,1) assert direction in (-1,1)
src_pane = self._get_focused_pane() src_pane = self._get_focused_pane()
if src_pane != None: if src_pane is not None:
dst_pane = src_pane + direction dst_pane = src_pane + direction
assert dst_pane >= 0 and dst_pane < self.num_panes assert dst_pane >= 0 and dst_pane < self.num_panes
paths = self._get_selected_paths(src_pane) paths = self._get_selected_paths(src_pane)
paths.reverse() paths.reverse()
model = self.model 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) it = model.get_iter(path)
name = model.value_path(it, src_pane) name = model.value_path(it, src_pane)
if name == None: if name is None:
continue continue
src = model.value_path(it, src_pane) src = model.value_path(it, src_pane)
dst = model.value_path(it, dst_pane) dst = model.value_path(it, dst_pane)
...@@ -562,7 +562,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -562,7 +562,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
""" """
# reverse so paths dont get changed # reverse so paths dont get changed
pane = self._get_focused_pane() pane = self._get_focused_pane()
if pane != None: if pane is not None:
paths = self._get_selected_paths(pane) paths = self._get_selected_paths(pane)
paths.reverse() paths.reverse()
for path in paths: for path in paths:
...@@ -584,7 +584,8 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -584,7 +584,8 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
def on_treeview_cursor_changed(self, *args): def on_treeview_cursor_changed(self, *args):
pane = self._get_focused_pane() pane = self._get_focused_pane()
if pane == None: return if pane is None:
return
paths = self._get_selected_paths(pane) paths = self._get_selected_paths(pane)
if len(paths) > 0: if len(paths) > 0:
def rwx(mode): def rwx(mode):
...@@ -619,7 +620,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -619,7 +620,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
elif gtk.keysyms.Left == event.keyval: elif gtk.keysyms.Left == event.keyval:
if pane-1 >= 0: if pane-1 >= 0:
tree = self.treeview[pane-1] tree = self.treeview[pane-1]
if tree != None: if tree is not None:
paths = self._get_selected_paths(pane) paths = self._get_selected_paths(pane)
view.get_selection().unselect_all() view.get_selection().unselect_all()
tree.grab_focus() tree.grab_focus()
...@@ -690,7 +691,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -690,7 +691,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
self.delete_selected() self.delete_selected()
def on_button_open_clicked(self, button): def on_button_open_clicked(self, button):
pane = self._get_focused_pane() pane = self._get_focused_pane()
if pane != None: if pane is not None:
m = self.model m = self.model
files = [ m.value_path( m.get_iter(p), pane ) for p in self._get_selected_paths(pane) ] files = [ m.value_path( m.get_iter(p), pane ) for p in self._get_selected_paths(pane) ]
self._open_files(files) self._open_files(files)
...@@ -725,7 +726,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -725,7 +726,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
def on_filter_hide_current_clicked(self, button): def on_filter_hide_current_clicked(self, button):
pane = self._get_focused_pane() pane = self._get_focused_pane()
if pane != None: if pane is not None:
paths = self._get_selected_paths(pane) paths = self._get_selected_paths(pane)
paths.reverse() paths.reverse()
for p in paths: for p in paths:
...@@ -735,7 +736,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -735,7 +736,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
# Selection # Selection
# #
def _get_selected_paths(self, pane): def _get_selected_paths(self, pane):
assert pane != None assert pane is not None
return self.treeview[pane].get_selection().get_selected_rows()[1] return self.treeview[pane].get_selection().get_selected_rows()[1]
# #
......
...@@ -626,7 +626,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -626,7 +626,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
panetext = [self._filter_text(p) for p in panetext] panetext = [self._filter_text(p) for p in panetext]
lines = map(lambda x: x.split("\n"), panetext) lines = map(lambda x: x.split("\n"), panetext)
step = self.linediffer.set_sequences_iter(lines) step = self.linediffer.set_sequences_iter(lines)
while step.next() == None: while step.next() is None:
yield 1 yield 1
if self.num_panes > 1 and self.linediffer.sequences_identical(): if self.num_panes > 1 and self.linediffer.sequences_identical():
......
...@@ -50,7 +50,7 @@ def cmdout(cmd, text=None, **kwargs): ...@@ -50,7 +50,7 @@ def cmdout(cmd, text=None, **kwargs):
def shelljoin( command ): def shelljoin( command ):
def quote(s): 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 ] ) return " ".join( [ quote(x) for x in command ] )
def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK, extrabuttons=()): def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK, extrabuttons=()):
......
...@@ -120,13 +120,13 @@ class FindBar(gnomeglade.Component): ...@@ -120,13 +120,13 @@ class FindBar(gnomeglade.Component):
else: else:
if backwards == False: if backwards == False:
match = pattern.search(text, insert.get_offset() + start_offset) 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) match = pattern.search(text, 0)
else: else:
match = None match = None
for m in pattern.finditer(text, 0, insert.get_offset()): for m in pattern.finditer(text, 0, insert.get_offset()):
match = m match = m
if match == None and wrap: if match is None and wrap:
for m in pattern.finditer(text, insert.get_offset()): for m in pattern.finditer(text, insert.get_offset()):
match = m match = m
if match: if match:
......
...@@ -72,7 +72,7 @@ class UndoSequence(gobject.GObject): ...@@ -72,7 +72,7 @@ class UndoSequence(gobject.GObject):
""" """
if hasattr(self, "group"): if hasattr(self, "group"):
assert self.group == None assert self.group is None
if self.can_undo(): if self.can_undo():
self.emit('can-undo', 0) self.emit('can-undo', 0)
if self.can_redo(): if self.can_redo():
...@@ -99,7 +99,7 @@ class UndoSequence(gobject.GObject): ...@@ -99,7 +99,7 @@ class UndoSequence(gobject.GObject):
action -- A class with two callable attributes: 'undo' and 'redo' action -- A class with two callable attributes: 'undo' and 'redo'
which are called by this sequence during an undo or 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_undo = self.can_undo()
could_redo = self.can_redo() could_redo = self.can_redo()
self.actions[self.next_redo:] = [] self.actions[self.next_redo:] = []
...@@ -161,8 +161,8 @@ class UndoSequence(gobject.GObject): ...@@ -161,8 +161,8 @@ class UndoSequence(gobject.GObject):
Raises an AssertionError if there was not a matching call to Raises an AssertionError if there was not a matching call to
begin_group(). begin_group().
""" """
assert self.group != None assert self.group is not None
if self.group.group != None: if self.group.group is not None:
self.group.end_group() self.group.end_group()
else: else:
group = self.group group = self.group
...@@ -177,8 +177,8 @@ class UndoSequence(gobject.GObject): ...@@ -177,8 +177,8 @@ class UndoSequence(gobject.GObject):
Raises an AssertionError if there was no a matching call to begin_group(). Raises an AssertionError if there was no a matching call to begin_group().
""" """
assert self.group != None assert self.group is not None
if self.group.group != None: if self.group.group is not None:
self.group.abort_group() self.group.abort_group()
else: else:
self.group = None self.group = None
......
...@@ -93,7 +93,7 @@ class GConfPreferences(object): ...@@ -93,7 +93,7 @@ class GConfPreferences(object):
self._gconf.notify_add(rootkey, self._on_preference_changed) self._gconf.notify_add(rootkey, self._on_preference_changed)
for key, value in self._prefs.items(): for key, value in self._prefs.items():
gval = self._gconf.get_without_default("%s/%s" % (rootkey, key) ) 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 )() value.current = getattr( gval, "get_%s" % value.type )()
def __getattr__(self, attr): def __getattr__(self, attr):
...@@ -121,7 +121,7 @@ class GConfPreferences(object): ...@@ -121,7 +121,7 @@ class GConfPreferences(object):
except KeyError: # unknown key, we don't care about it except KeyError: # unknown key, we don't care about it
pass pass
else: 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)() newval = getattr(entry.value, "get_%s" % valuestruct.type)()
setattr( self, attr, newval) setattr( self, attr, newval)
else: # value has been deleted else: # value has been deleted
......
...@@ -101,12 +101,12 @@ class Vc(_vc.CachedVc): ...@@ -101,12 +101,12 @@ class Vc(_vc.CachedVc):
bzrfiles[name] = 1 bzrfiles[name] = 1
for f,path in files: for f,path in files:
if f not in bzrfiles: 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 state = _vc.STATE_NORMAL
retfiles.append( _vc.File(path, f, state, "") ) retfiles.append( _vc.File(path, f, state, "") )
for d,path in dirs: for d,path in dirs:
if d not in bzrfiles: 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 state = _vc.STATE_NORMAL
retdirs.append( _vc.Dir(path, d, state) ) retdirs.append( _vc.Dir(path, d, state) )
return retdirs, retfiles return retdirs, retfiles
...@@ -158,11 +158,11 @@ class Vc(_vc.Vc): ...@@ -158,11 +158,11 @@ class Vc(_vc.Vc):
for f,path in files: for f,path in files:
if f not in cvsfiles: 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, "") ) retfiles.append( _vc.File(path, f, state, "") )
for d,path in dirs: for d,path in dirs:
if d not in cvsfiles: 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) ) retdirs.append( _vc.Dir(path, d, state) )
return retdirs, retfiles return retdirs, retfiles
...@@ -83,12 +83,12 @@ class Vc(_vc.Vc): ...@@ -83,12 +83,12 @@ class Vc(_vc.Vc):
hgfiles[name] = 1 hgfiles[name] = 1
for f,path in files: for f,path in files:
if f not in hgfiles: 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 state = _vc.STATE_NORMAL
retfiles.append( _vc.File(path, f, state, "") ) retfiles.append( _vc.File(path, f, state, "") )
for d,path in dirs: for d,path in dirs:
if d not in hgfiles: 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 state = _vc.STATE_NORMAL
retdirs.append( _vc.Dir(path, d, state) ) retdirs.append( _vc.Dir(path, d, state) )
......
...@@ -393,7 +393,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component): ...@@ -393,7 +393,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
s = self.treeview.get_selection() s = self.treeview.get_selection()
s.selected_foreach(gather) s.selected_foreach(gather)
# remove empty entries and remove trailing slashes # 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): def _command_iter(self, command, files, refresh):
"""Run 'command' on 'files'. Return a tuple of the directory the """Run 'command' on 'files'. Return a tuple of the directory the
...@@ -415,7 +415,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component): ...@@ -415,7 +415,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
self.consolestream.write( misc.shelljoin(command+files) + " (in %s)\n" % workdir) self.consolestream.write( misc.shelljoin(command+files) + " (in %s)\n" % workdir)
readfunc = misc.read_pipe_iter(command + files, self.consolestream, workdir=workdir).next readfunc = misc.read_pipe_iter(command + files, self.consolestream, workdir=workdir).next
try: try:
while r == None: while r is None:
r = readfunc() r = readfunc()
self.consolestream.write(r) self.consolestream.write(r)
yield 1 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