Code optimizations wrt handling of None - bug 2212

svn: r10811
This commit is contained in:
Gerald Britton
2008-06-16 15:01:46 +00:00
parent 47095b4e98
commit 4982292774
124 changed files with 379 additions and 377 deletions

View File

@@ -1717,7 +1717,7 @@ class GrampsDbBase(Callback):
if self.undoindex >= _UNDO_SIZE or self.readonly:
return False
if self.translist[self.undoindex+1] == None:
if self.translist[self.undoindex+1] is None:
return False
return True
@@ -1811,7 +1811,7 @@ class GrampsDbBase(Callback):
pass
def undo_data(self, data, handle, db_map, signal_root):
if data == None:
if data is None:
self.emit(signal_root + '-delete', ([handle], ))
del db_map[handle]
else:
@@ -1924,7 +1924,7 @@ class GrampsDbBase(Callback):
def set_default_person_handle(self, handle):
"""Set the default Person to the passed instance."""
if (self.metadata != None) and (not self.readonly):
if (self.metadata is not None) and (not self.readonly):
self.metadata['default'] = str(handle)
def get_default_person(self):
@@ -1932,13 +1932,13 @@ class GrampsDbBase(Callback):
person = self.get_person_from_handle(self.get_default_handle())
if person:
return person
elif (self.metadata != None) and (not self.readonly):
elif (self.metadata is not None) and (not self.readonly):
self.metadata['default'] = None
return None
def get_default_handle(self):
"""Return the default Person of the database."""
if self.metadata != None:
if self.metadata is not None:
return self.metadata.get('default')
return None
@@ -2252,17 +2252,17 @@ class GrampsDbBase(Callback):
def set_mediapath(self, path):
"""Set the default media path for database, path should be utf-8."""
if (self.metadata != None) and (not self.readonly):
if (self.metadata is not None) and (not self.readonly):
self.metadata['mediapath'] = path
def get_mediapath(self):
"""Return the default media path of the database."""
if self.metadata != None:
if self.metadata is not None:
return self.metadata.get('mediapath', None)
return None
def set_column_order(self, col_list, name):
if (self.metadata != None) and (not self.readonly):
if (self.metadata is not None) and (not self.readonly):
self.metadata[name] = col_list
def set_person_column_order(self, col_list):
@@ -2321,7 +2321,7 @@ class GrampsDbBase(Callback):
self.set_column_order(col_list, NOTE_COL_KEY)
def __get_column_order(self, name, default):
if self.metadata == None:
if self.metadata is None:
return default
else:
cols = self.metadata.get(name, default)
@@ -2496,7 +2496,7 @@ class GrampsDbBase(Callback):
# Find which tables to iterate over
if (include_classes == None):
if (include_classes is None):
the_tables = primary_tables.keys()
else:
the_tables = include_classes
@@ -2627,7 +2627,7 @@ class Transaction:
"""
self.last = self.db.append(
cPickle.dumps((obj_type, handle, old_data, new_data), 1))
if self.first == None:
if self.first is None:
self.first = self.last
def get_recnos(self):

View File

@@ -262,7 +262,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def __has_handle(self, table, handle):
try:
return table.get(str(handle), txn=self.txn) != None
return table.get(str(handle), txn=self.txn) is not None
except DBERRS, msg:
self.__log_error()
raise Errors.DbError(msg)
@@ -537,7 +537,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
# Start transaction
the_txn = self.env.txn_begin()
if gstats == None:
if gstats is None:
# New database. Set up the current version.
self.metadata.put('version', _DBVERSION, txn=the_txn)
elif not self.metadata.has_key('version'):
@@ -876,7 +876,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
data = self.reference_map.get(data)
else:
data = pickle.loads(data)
if include_classes == None or \
if include_classes is None or \
KEY_TO_CLASS_MAP[data[0][0]] in include_classes:
yield (KEY_TO_CLASS_MAP[data[0][0]], data[0][1])
@@ -1664,7 +1664,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def undo_reference(self, data, handle):
try:
if data == None:
if data is None:
self.reference_map.delete(handle, txn=self.txn)
else:
self.reference_map.put(handle, data, txn=self.txn)
@@ -1674,7 +1674,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def undo_data(self, data, handle, db_map, signal_root):
try:
if data == None:
if data is None:
self.emit(signal_root + '-delete', ([handle],))
db_map.delete(handle, txn=self.txn)
else:

View File

@@ -97,7 +97,7 @@ class Span:
) # number of months, for sorting
def __eq__(self, other):
if other == None:
if other is None:
return False
return self.diff_tuple == other.diff_tuple
@@ -204,15 +204,15 @@ class Date:
raise AttributeError, "invalid args to Date: %s" % source
#### ok, process either date or tuple
if isinstance(source, tuple):
if calendar == None:
if calendar is None:
self.calendar = Date.CAL_GREGORIAN
else:
self.calendar = self.lookup_calendar(calendar)
if modifier == None:
if modifier is None:
self.modifier = Date.MOD_NONE
else:
self.modifier = self.lookup_modifier(modifier)
if quality == None:
if quality is None:
self.quality = Date.QUAL_NONE
else:
self.quality = self.lookup_quality(quality)
@@ -222,9 +222,9 @@ class Date:
self.newyear = 0
self.set_yr_mon_day(*source)
elif isinstance(source, str) and source != "":
if (calendar != None or
modifier != None or
quality != None):
if (calendar is not None or
modifier is not None or
quality is not None):
raise AttributeError("can't set calendar, modifier, or "
"quality with string date")
import DateHandler
@@ -972,7 +972,7 @@ class Date:
year = max(value[Date._POS_YR], 1)
month = max(value[Date._POS_MON], 1)
day = max(value[Date._POS_DAY], 1)
if year == 0 and month == 0 and day == 0:
if year == month == 0 and day == 0:
self.sortval = 0
else:
func = Date._calendar_convert[calendar]
@@ -995,7 +995,7 @@ class Date:
year = max(self.dateval[Date._POS_YR], 1)
month = max(self.dateval[Date._POS_MON], 1)
day = max(self.dateval[Date._POS_DAY], 1)
if year == 0 and month == 0 and day == 0:
if year == month == 0 and day == 0:
self.sortval = 0
else:
func = Date._calendar_convert[self.calendar]

View File

@@ -57,7 +57,7 @@ class DateBase:
"""
Convert the object to a serialized tuple of data.
"""
if self.date == None or (self.date.is_empty() and not self.date.text):
if self.date is None or (self.date.is_empty() and not self.date.text):
date = None
else:
date = self.date.serialize(no_text_date)

View File

@@ -255,7 +255,7 @@ class Event(SourceBase, NoteBase, MediaBase, AttributeBase,
@returns: True if the Events are equal
@rtype: bool
"""
if other == None:
if other is None:
other = Event (None)
if self.__type != other.__type or \
@@ -314,3 +314,4 @@ class Event(SourceBase, NoteBase, MediaBase, AttributeBase,
"""
return self.__description
description = property(get_description, set_description, None, 'Returns or sets description of the event')

View File

@@ -204,3 +204,4 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase):
"""
self.__role.set(role)
role = property(get_role, set_role, None, 'Returns or sets role property')

View File

@@ -56,6 +56,6 @@ class FamilyRelType(GrampsType):
]
def __init__(self, value=None):
if value == None:
if value is None:
value = self.UNKNOWN
GrampsType.__init__(self, value)

View File

@@ -44,7 +44,7 @@ class GenderStats:
indicating the gender of the person.
"""
def __init__ (self, stats={}):
if stats == None:
if stats is None:
self.stats = {}
else:
self.stats = stats

View File

@@ -95,7 +95,7 @@ class Place(SourceBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
@rtype: tuple
"""
if self.main_loc == None or self.main_loc.serialize() == _EMPTY_LOC:
if self.main_loc is None or self.main_loc.serialize() == _EMPTY_LOC:
main_loc = None
else:
main_loc = self.main_loc.serialize()

View File

@@ -226,7 +226,7 @@ class Tester(unittest.TestCase):
"""
Tests two GRAMPS dates to see if they match.
"""
if expected2 == None:
if expected2 is None:
expected2 = expected1
date1 = _dp.parse(d1)
date2 = _dp.parse(d2)

View File

@@ -76,7 +76,7 @@ class LivingProxyDb(ProxyDbBase):
"""
ProxyDbBase.__init__(self, dbase)
self.mode = mode
if current_year != None:
if current_year is not None:
self.current_date = Date()
self.current_date.set_year(current_year)
else:

View File

@@ -343,7 +343,7 @@ class Callback(object):
self._current_signals.append(signal_name)
# check that args is a tuple. This is a common programming error.
if not (isinstance(args, tuple) or args == None):
if not (isinstance(args, tuple) or args is None):
self._warn("Signal emitted with argument that is not a tuple.\n"
" emit() takes two arguments, the signal name and a \n"
" tuple that contains the arguments that are to be \n"
@@ -359,7 +359,7 @@ class Callback(object):
# type check arguments
arg_types = self.__signal_map[signal_name]
if arg_types == None and len(args) > 0:
if arg_types is None and len(args) > 0:
self._warn("Signal emitted with "
"wrong number of args: %s\n"
" from: file: %s\n"
@@ -378,7 +378,7 @@ class Callback(object):
% ((str(signal_name), ) + inspect.stack()[1][1:4]))
return
if arg_types != None:
if arg_types is not None:
for i in range(0, len(arg_types)):
if not isinstance(args[i], arg_types[i]):
self._warn("Signal emitted with "

View File

@@ -73,7 +73,7 @@ def delete_person_from_database(db, person, trans):
def remove_family_relationships(db, family_handle, trans=None):
family = db.get_family_from_handle(family_handle)
if trans == None:
if trans is None:
need_commit = True
trans = db.transaction_begin()
else:
@@ -105,7 +105,7 @@ def remove_parent_from_family(db, person_handle, family_handle, trans=None):
person = db.get_person_from_handle(person_handle)
family = db.get_family_from_handle(family_handle)
if trans == None:
if trans is None:
need_commit = True
trans = db.transaction_begin()
else:
@@ -144,7 +144,7 @@ def remove_child_from_family(db, person_handle, family_handle, trans=None):
person.remove_parent_family_handle(family_handle)
family.remove_child_handle(person_handle)
if trans == None:
if trans is None:
need_commit = True
trans = db.transaction_begin()
else:
@@ -186,7 +186,7 @@ def add_child_to_family(db, family, child,
family.add_child_ref(cref)
child.add_parent_family_handle(family.handle)
if trans == None:
if trans is None:
need_commit = True
trans = db.transaction_begin()
else:

View File

@@ -83,14 +83,14 @@ class ProgressMonitor(object):
self._title = title
self._popup_time = popup_time
if self._popup_time == None:
if self._popup_time is None:
self._popup_time = self.__class__.__default_popup_time
self._status_stack = [] # list of current status objects
self._dlg = None
def _get_dlg(self):
if self._dlg == None:
if self._dlg is None:
self._dlg = self._dialog_class(self._dialog_class_params,
self._title)
@@ -134,7 +134,7 @@ class ProgressMonitor(object):
if facade.active:
dlg = self._get_dlg()
if facade.pbar_idx == None:
if facade.pbar_idx is None:
facade.pbar_idx = dlg.add(facade.status_obj)
dlg.show()