Skip to content

Commit

Permalink
Comprehensively use 'is None' and 'is not None'
Browse files Browse the repository at this point in the history
Use 'is None' and 'is not None' everywhere; this was recommended
by Jonathan Griffitts in http://www.reinteract.org/trac/ticket/71.
Going ahead and doing it now was inspired by the xmlrpc horror
in http://www.reinteract.org/trac/ticket/77.

No Reinteract object will ever be badly behaved enough to try and
make a remote procedure call when its __eq__() method is called,
but it's easier to make a blanket search and replace than audit
everywhere for user-supplied objects.
  • Loading branch information
owtaylor committed Apr 3, 2009
1 parent 73a3d62 commit 2b71670
Show file tree
Hide file tree
Showing 32 changed files with 136 additions and 136 deletions.
4 changes: 2 additions & 2 deletions lib/reinteract/about_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _find_url_open_program():

for progname in ['xdg-open', 'htmlview', 'gnome-open']:
path = _find_program_in_path(progname)
if path != None:
if path is not None:
return path
return None

Expand All @@ -42,7 +42,7 @@ def _open_url(dialog, url):

class AboutDialog(gtk.AboutDialog):
def __init__(self):
if _find_url_open_program() != None:
if _find_url_open_program() is not None:
gtk.about_dialog_set_url_hook(_open_url)

gtk.AboutDialog.__init__(self)
Expand Down
4 changes: 2 additions & 2 deletions lib/reinteract/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def find_notebook_path(self, path):
return None, None

tmp = parent
if relative == None:
if relative is None:
relative = basename
else:
relative = os.path.join(basename, relative)
Expand Down Expand Up @@ -163,7 +163,7 @@ def open_path(self, path):
def create_notebook(self, path, description=None):
os.makedirs(path)
notebook = Notebook(path)
if description != None:
if description is not None:
notebook.info.description = description
window = self.__make_notebook_window(notebook)
window.show()
Expand Down
8 changes: 4 additions & 4 deletions lib/reinteract/base_notebook_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ def __init__(self, notebook):
self.open_file(file)

current_file_editor = None
if current_file != None:
if current_file is not None:
filename = os.path.join(notebook.folder, current_file)
for editor in self.editors:
if editor.filename == filename:
current_file_editor = editor

if current_file_editor == None and len(self.editors) > 0:
if current_file_editor is None and len(self.editors) > 0:
current_file_editor = self.editors[0]

if current_file_editor != None:
if current_file_editor is not None:
self._make_editor_current(current_file_editor)
current_file_editor.view.grab_focus()

Expand Down Expand Up @@ -199,7 +199,7 @@ def _update_open_files(self):

def _update_current_file(self):
file = self.current_editor.file
if file != None:
if file is not None:
self.state.set_current_file(file.path)
else:
self.state.set_current_file(None)
Expand Down
8 changes: 4 additions & 4 deletions lib/reinteract/base_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def on_open(self, action):
if response == gtk.RESPONSE_OK:
filename = chooser.get_filename()

if filename != None:
if filename is not None:
application.open_path(filename)

chooser.destroy()
Expand Down Expand Up @@ -265,9 +265,9 @@ def show(self):
self.window.show()

def update_sensitivity(self):
self._set_action_sensitive('calculate', self.current_editor != None and self.current_editor.needs_calculate)
self._set_action_sensitive('break', self.current_editor != None and self.current_editor.state == NotebookFile.EXECUTING)
self._set_action_sensitive('calculate', self.current_editor is not None and self.current_editor.needs_calculate)
self._set_action_sensitive('break', self.current_editor is not None and self.current_editor.state == NotebookFile.EXECUTING)

# This seems more annoying than useful. gedit doesn't desensitize save
# self._set_action_sensitive('save', self.current_editor != None and self.current_editor.modified)
# self._set_action_sensitive('save', self.current_editor is not None and self.current_editor.modified)

4 changes: 2 additions & 2 deletions lib/reinteract/chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __repr__(self):

def set_lines(self, lines):
range = self.tokenized.set_lines(lines)
if range == None:
if range is None:
return False

if range[0] != range[1]: # non-empty range ... empty=truncation
Expand All @@ -112,7 +112,7 @@ def set_lines(self, lines):
return True

def mark_for_execute(self):
if self.statement != None and not self.needs_execute:
if self.statement is not None and not self.needs_execute:
self.statement.mark_for_execute()
self.needs_execute = True
self.status_changed = True
Expand Down
4 changes: 2 additions & 2 deletions lib/reinteract/completion_popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __update_completions(self, spontaneous=False):
self.__in_change = True
self.__tree_model.clear()
line, offset = buf.iter_to_pos(buf.get_iter_at_mark(buf.get_insert()), adjust=ADJUST_NONE)
if line == None:
if line is None:
completions = []
else:
if spontaneous:
Expand Down Expand Up @@ -117,7 +117,7 @@ def __update_doc_popup(self):
# object, but it's distracting to show the class docs on int
# for every integer constant, etc, which is what the DocPopup
# does currently.
if (obj == None or is_data_object(obj)):
if (obj is None or is_data_object(obj)):
self.__doc_popup.popdown()
return

Expand Down
2 changes: 1 addition & 1 deletion lib/reinteract/custom_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def on_activate(menu):

chooser.destroy()

if filename != None:
if filename is not None:
save_callback(filename)

menu_item.connect('activate', on_activate)
Expand Down
10 changes: 5 additions & 5 deletions lib/reinteract/data_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __format_separate(sequence, open, close, nl):
lines = 1
last_str, last_lines = None, 0
for str, item_lines in sequence:
if last_str != None:
if last_str is not None:
# Process the last item, we'll have one more after it
new_lines = lines + last_lines

Expand All @@ -79,7 +79,7 @@ def __format_separate(sequence, open, close, nl):
last_str = str
last_lines = item_lines

if last_str != None:
if last_str is not None:
buf.write(last_str)

buf.write(close)
Expand All @@ -105,7 +105,7 @@ def __format_wrapped(sequence, open, close, nl):
if len(str) > _MAX_WRAPPED_ITEM_LEN:
return None

if last_str != None:
if last_str is not None:
# Process the last item, we'll have one more after it
new_available_width = available_width - (len(last_str) + 1) # len(last_str) + len(",")
if count_on_line > 0:
Expand Down Expand Up @@ -138,7 +138,7 @@ def __format_wrapped(sequence, open, close, nl):
last_str = str
last_lines = item_lines

if last_str != None:
if last_str is not None:
new_available_width = available_width - (len(last_str) + len(close))

if count_on_line > 0:
Expand Down Expand Up @@ -172,7 +172,7 @@ def __format_sequence(obj, open, close, nl, object_stack):

seq = (__format(x, nl, object_stack) for x in obj)
result = __format_wrapped(seq, open, close, nl)
if result == None:
if result is None:
seq = (__format(x, nl, object_stack) for x in obj)
result = __format_separate(seq, open, close, nl)

Expand Down
2 changes: 1 addition & 1 deletion lib/reinteract/doc_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def insert_docs(buf, iter, obj, bold_tag):
pos = 0
while True:
m = BOLD_RE.search(document, pos)
if m == None:
if m is None:
# Strip the trailing newline; this isn't very justifiable in general terms,
# but matches what we need in Reinteract
if document.endswith("\n"):
Expand Down
2 changes: 1 addition & 1 deletion lib/reinteract/doc_popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def set_target(self, target):
buf = self.__view.get_buffer()
buf.delete(buf.get_start_iter(), buf.get_end_iter())

if target != None:
if target is not None:
if data_format.is_data_object(target):
data_format.insert_formatted(buf, buf.get_start_iter(), target, self.__heading_type_tag, self.__inline_type_tag, self.__value_tag)
else:
Expand Down
14 changes: 7 additions & 7 deletions lib/reinteract/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, notebook):
#######################################################

def _clear_unsaved(self):
if self._unsaved_index != None:
if self._unsaved_index is not None:
application.free_unsaved_index(self._unsaved_index)
self._unsaved_index = None

Expand All @@ -53,7 +53,7 @@ def __prompt_for_name(self, title, save_button_text, action, check_name=None):
builder = SaveFileBuilder(title, self._get_display_name(), save_button_text, check_name)
builder.dialog.set_transient_for(self.widget.get_toplevel())

if self._get_filename() != None:
if self._get_filename() is not None:
builder.name_entry.set_text(os.path.basename(self._get_filename()))

builder.prompt_for_name(self.notebook.folder, self._get_extension(), action)
Expand Down Expand Up @@ -90,7 +90,7 @@ def _save(self, filename):
#######################################################

def close(self):
if self._unsaved_index != None:
if self._unsaved_index is not None:
application.free_unsaved_index(self._unsaved_index)
self._unsaved_index = None

Expand All @@ -107,7 +107,7 @@ def confirm_discard(self, before_quit=False):
message_format = self.DISCARD_FORMAT
continue_button_text = '_Discard'

if self._get_filename() == None:
if self._get_filename() is None:
save_button_text = gtk.STOCK_SAVE_AS
else:
save_button_text = gtk.STOCK_SAVE
Expand Down Expand Up @@ -141,10 +141,10 @@ def load(self, filename):
raise NotImplementedError()

def save(self, filename=None):
if filename == None:
if filename is None:
filename = self._get_filename()

if filename == None:
if filename is None:
def action(fullname):
self._save(fullname)
self._clear_unsaved()
Expand All @@ -155,7 +155,7 @@ def action(fullname):
self._save(filename)

def rename(self):
if self._get_filename() == None:
if self._get_filename() is None:
self.save()
return

Expand Down
4 changes: 2 additions & 2 deletions lib/reinteract/editor_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __save_as(self):
if response == gtk.RESPONSE_OK:
filename = chooser.get_filename()

if filename != None:
if filename is not None:
self.current_editor.save(filename)
self.path = filename
self.notebook.set_path([os.path.dirname(filename)])
Expand All @@ -111,7 +111,7 @@ def __update_title(self, *args):
#######################################################

def on_save(self, action):
if self.current_editor.filename == None:
if self.current_editor.filename is None:
self.__save_as()
else:
self.current_editor.save()
Expand Down
16 changes: 8 additions & 8 deletions lib/reinteract/file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def _next_row_depthfirst(model, iter):
if model.iter_has_child(iter):
return model.iter_children(iter)

while iter != None:
while iter is not None:
next = model.iter_next(iter)
if next != None:
if next is not None:
return next

iter = model.iter_parent(iter)
Expand All @@ -143,9 +143,9 @@ def _remove_row_depthfirst(model, iter):
if model.remove(iter):
return iter

while parent != None:
while parent is not None:
next = model.iter_next(parent)
if next != None:
if next is not None:
return next

parent = model.iter_parent(parent)
Expand Down Expand Up @@ -215,7 +215,7 @@ def do_button_press_event(self, event):
event.button == 3 or (event.button == 1 and event.state == gtk.gdk.CONTROL_MASK)):

info = self.get_path_at_pos(int(event.x), int(event.y))
if info == None:
if info is None:
return False

path, column, cell_x, cell_y = info
Expand Down Expand Up @@ -428,7 +428,7 @@ def __rescan(self):
for (item, new_depth) in self.__iter_items():
# Delete old items that are logically before the next item
found_item = False
while next_old != None:
while next_old is not None:
old_item = self.__model.get_value(next_old, 0)
c = cmp(item, old_item)
if c < 0:
Expand Down Expand Up @@ -472,7 +472,7 @@ def __rescan(self):
parent = iter
depth += 1

while next_old != None:
while next_old is not None:
next_old = _remove_row_depthfirst(self.__model, next_old)

self.set_show_expanders(seen_folders)
Expand All @@ -491,7 +491,7 @@ def select_file(self, file):
"""

iter = self.__iter_for_file(file)
if iter == None:
if iter is None:
return

self.set_cursor(self.__model.get_path(iter), self.get_column(0))
Expand Down
2 changes: 1 addition & 1 deletion lib/reinteract/library_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __update_font(self, *arg):
#######################################################

def _get_display_name(self):
if self.buf.worksheet.filename == None:
if self.buf.worksheet.filename is None:
return "Unsaved Library %d" % self._unsaved_index
else:
return os.path.basename(self.buf.worksheet.filename)
Expand Down
2 changes: 1 addition & 1 deletion lib/reinteract/mini_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __update_pages(self):

open_editors = {}
for editor in self.editors:
if editor.file == None:
if editor.file is None:
items.append(self.__create_editor_item(editor))
else:
open_editors[editor.file.path] = editor
Expand Down
4 changes: 2 additions & 2 deletions lib/reinteract/new_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def run(parent=None):
error_message = "<big><b>Please choose a different name</b></big>"
error_detail = e.message

if error_message == None:
if error_message is None:
if builder.other_folder_radio_button.get_active():
parent_folder = builder.other_folder_chooser.get_filename()
else:
Expand All @@ -69,7 +69,7 @@ def run(parent=None):
error_message = "<big><b>Please choose a different name</b></big>"
error_detail = "'%s' already exists" % name

if error_message == None:
if error_message is None:
try:
builder.dialog.hide()
description = builder.description_text_view.get_buffer().props.text.strip()
Expand Down
Loading

0 comments on commit 2b71670

Please sign in to comment.