From 998908175fd00c175f88b2b7ed83b4affb0094c4 Mon Sep 17 00:00:00 2001 From: Zsolt Foldvari Date: Sun, 25 May 2008 19:55:47 +0000 Subject: [PATCH] Issue #0002175: Change type() expressions to isinstance() expressions. Patch from Gerald Britton svn: r10762 --- src/AutoComp.py | 4 ++-- src/BaseDoc.py | 2 +- src/Config/_GrampsGconfKeys.py | 6 +++--- src/DataViews/GrampletView.py | 6 +++--- src/DbLoader.py | 2 +- src/DisplayTabs/_GrampsTab.py | 2 +- src/Editors/_EditMediaRef.py | 2 +- src/Errors.py | 2 +- src/Filters/Rules/_Rule.py | 16 ++++++++-------- src/Filters/_FilterList.py | 2 +- src/GrampsDbUtils/_GedcomStageOne.py | 4 ++-- src/GrampsDbUtils/_GrampsBSDDB.py | 2 +- src/GrampsDbUtils/_ReadGedcom.py | 2 +- src/ManagedWindow.py | 14 +++++++------- src/Models/_ListCursor.py | 2 +- src/Models/_PathCursor.py | 2 +- src/PluginUtils/_Options.py | 2 +- src/PluginUtils/_Tool.py | 6 +++--- src/QuickReports.py | 2 +- src/ReportBase/_CommandLineReport.py | 2 +- src/ReportBase/_GraphvizReportDialog.py | 4 ++-- src/ReportBase/_ReportDialog.py | 4 ++-- src/ReportBase/_ReportUtils.py | 2 +- src/Simple/_SimpleAccess.py | 2 +- src/Simple/_SimpleTable.py | 4 ++-- src/TreeTips.py | 2 +- src/Utils.py | 4 ++-- src/gen/lib/attrbase.py | 2 +- src/gen/lib/date.py | 16 ++++++++-------- src/gen/lib/grampstype.py | 12 ++++++------ src/gen/lib/markertype.py | 6 +++--- src/gen/lib/person.py | 2 +- src/gen/utils/callback.py | 4 ++-- src/gen/utils/test/callback_test.py | 10 +++++----- src/plugins/AncestorTree.py | 6 +++--- src/plugins/BookReport.py | 2 +- src/plugins/Calendar.py | 4 ++-- src/plugins/Check.py | 8 ++++---- src/plugins/CmdRef.py | 2 +- src/plugins/DescendTree.py | 4 ++-- src/plugins/SameSurnames.py | 2 +- src/plugins/WebCal.py | 4 ++-- src/plugins/rel_cs.py | 2 +- src/plugins/rel_da.py | 3 +-- src/plugins/rel_es.py | 3 +-- src/plugins/rel_fi.py | 3 +-- src/plugins/rel_hu.py | 3 +-- src/plugins/rel_it.py | 3 +-- src/plugins/rel_no.py | 3 +-- src/plugins/rel_pt.py | 2 +- src/plugins/rel_ru.py | 3 +-- src/plugins/rel_sk.py | 3 +-- src/widgets/monitoredwidgets.py | 2 +- 53 files changed, 105 insertions(+), 113 deletions(-) diff --git a/src/AutoComp.py b/src/AutoComp.py index 99d05c31a..d3c5974eb 100644 --- a/src/AutoComp.py +++ b/src/AutoComp.py @@ -167,10 +167,10 @@ class StandardCustomSelector: if self.additional: for event_type in self.additional: - if type(event_type) == str or type(event_type) == unicode : + if isinstance(event_type, basestring): if event_type: self.store.append(row=[self.custom_key, event_type]) - elif type(event_type) == tuple: + elif isinstance(event_type, tuple): if event_type[1]: self.store.append(row=[event_type[0], event_type[1]]) else: diff --git a/src/BaseDoc.py b/src/BaseDoc.py index 52b06aadf..30db052b5 100644 --- a/src/BaseDoc.py +++ b/src/BaseDoc.py @@ -872,7 +872,7 @@ class ParagraphStyle: return self.bmargin def set_tabs(self, tab_stops): - assert(type(tab_stops) == type([])) + assert isinstance(tab_stops, list) self.tabs = tab_stops def get_tabs(self): diff --git a/src/Config/_GrampsGconfKeys.py b/src/Config/_GrampsGconfKeys.py index 76c236d99..70470a1c0 100644 --- a/src/Config/_GrampsGconfKeys.py +++ b/src/Config/_GrampsGconfKeys.py @@ -164,10 +164,10 @@ def get_default(key, sample=''): value = client.get_default_from_schema(token) if value == None: raise Errors.GConfSchemaError("No default value for key "+key[1]) - if type(sample) in (str, unicode): + if isinstance(sample, basestring): return value.get_string() - elif type(sample) == int: + elif isinstance(sample, int): return value.get_int() - elif type(sample) == bool: + elif isinstance(sample, bool): return value.get_bool() return None diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index 2efbdd9ed..f3fdfeffb 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -364,7 +364,7 @@ class Gramplet(object): Runs the generator. """ if debug: print "%s _updater" % self.gui.title - if type(self._generator) != types.GeneratorType: + if not isinstance(self._generator, types.GeneratorType): self._idle_id = 0 return False try: @@ -925,7 +925,7 @@ class GrampletView(PageView.PersonNavView): elif key == "column": continue elif key == "row": continue elif key == "data": - if type(base_opts["data"]) not in [list, tuple]: + if not isinstance(base_opts["data"], (list, tuple)): fp.write(("data[0]=%s" + NL) % base_opts["data"]) else: cnt = 0 @@ -950,7 +950,7 @@ class GrampletView(PageView.PersonNavView): if key == "content": continue elif key == "title": continue elif key == "data": - if type(base_opts["data"]) not in [list, tuple]: + if not isinstance(base_opts["data"], (list, tuple)): fp.write(("data[0]=%s" + NL) % base_opts["data"]) else: cnt = 0 diff --git a/src/DbLoader.py b/src/DbLoader.py index ffb1e6c6d..6fe5cc3ca 100644 --- a/src/DbLoader.py +++ b/src/DbLoader.py @@ -204,7 +204,7 @@ class DbLoader: """ - if type(filename) not in (str, unicode): + if not isinstance(filename, basestring): return True filename = os.path.normpath(os.path.abspath(filename)) diff --git a/src/DisplayTabs/_GrampsTab.py b/src/DisplayTabs/_GrampsTab.py index 09c8ba7e5..57fa19014 100644 --- a/src/DisplayTabs/_GrampsTab.py +++ b/src/DisplayTabs/_GrampsTab.py @@ -105,7 +105,7 @@ class GrampsTab(gtk.HBox): hbox = gtk.HBox() icon = self.get_icon_name() - if type(icon) == tuple: + if isinstance(icon, tuple): if icon[0] == 0: func = gtk.image_new_from_icon_name else: diff --git a/src/Editors/_EditMediaRef.py b/src/Editors/_EditMediaRef.py index ac0a2aa14..3b4ba796b 100644 --- a/src/Editors/_EditMediaRef.py +++ b/src/Editors/_EditMediaRef.py @@ -136,7 +136,7 @@ class EditMediaRef(EditReference): self.draw_preview() - if coord and type(coord) == tuple: + if coord and isinstance(coord, tuple): self.top.get_widget("corner1_x").set_value(coord[0]) self.top.get_widget("corner1_y").set_value(coord[1]) self.top.get_widget("corner2_x").set_value(coord[2]) diff --git a/src/Errors.py b/src/Errors.py index 139548138..f02932900 100644 --- a/src/Errors.py +++ b/src/Errors.py @@ -143,7 +143,7 @@ class DbError(Exception): """Error used to report that the request window is already displayed.""" def __init__(self, value): Exception.__init__(self) - if type(value) == tuple: + if isinstance(value, tuple): self.value = value[1] else: self.value = value diff --git a/src/Filters/Rules/_Rule.py b/src/Filters/Rules/_Rule.py index 55c14be37..53c1e7f05 100644 --- a/src/Filters/Rules/_Rule.py +++ b/src/Filters/Rules/_Rule.py @@ -40,8 +40,8 @@ class Rule: category = _('Miscellaneous filters') description = _('No description') - def __init__(self, list): - self.set_list(list) + def __init__(self, arg): + self.set_list(arg) def is_empty(self): return False @@ -51,13 +51,13 @@ class Rule: def reset(self): pass - - def set_list(self, list): - assert type(list) == type([]) or list == None, "Argument is not a list" - assert len(list) == len(self.labels), \ + + def set_list(self, arg): + assert isinstance(arg, list) or arg == None, "Argument is not a list" + assert len(arg) == len(self.labels), \ "Number of arguments does not match number of labels.\n"\ - "list: %s\nlabels: %s" % (list,self.labels) - self.list = list + "list: %s\nlabels: %s" % (arg,self.labels) + self.list = arg def values(self): return self.list diff --git a/src/Filters/_FilterList.py b/src/Filters/_FilterList.py index a2044057a..0ef228f13 100644 --- a/src/Filters/_FilterList.py +++ b/src/Filters/_FilterList.py @@ -57,7 +57,7 @@ class FilterList: return [] def add(self, namespace, filt): - assert(type(namespace)==str or type(namespace)==unicode) + assert(isinstance(namespace, basestring)) if namespace not in self.filter_namespaces.keys(): self.filter_namespaces[namespace] = [] diff --git a/src/GrampsDbUtils/_GedcomStageOne.py b/src/GrampsDbUtils/_GedcomStageOne.py index 0599631a2..742543a79 100644 --- a/src/GrampsDbUtils/_GedcomStageOne.py +++ b/src/GrampsDbUtils/_GedcomStageOne.py @@ -165,7 +165,7 @@ class StageOne: elif key in ("CHIL", "CHILD") and is_xref_value(value): add_to_list(self.famc, value[1:-1], current_family_id) elif key == 'CHAR' and not self.enc: - assert(type(value) == str or type(value) == unicode) + assert(isinstance(value, basestring)) self.enc = value def get_famc_map(self): @@ -190,7 +190,7 @@ class StageOne: """ Forces the encoding """ - assert(type(enc) == str or type(enc) == unicode) + assert(isinstance(enc, basestring)) self.enc = enc def get_person_count(self): diff --git a/src/GrampsDbUtils/_GrampsBSDDB.py b/src/GrampsDbUtils/_GrampsBSDDB.py index cc4e3402e..3e9c8ae52 100644 --- a/src/GrampsDbUtils/_GrampsBSDDB.py +++ b/src/GrampsDbUtils/_GrampsBSDDB.py @@ -2084,7 +2084,7 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback): if name == 'Note': # Special case: we are way down at the very bottom. # Create note, commit it, return a list with one handle. - if (type(obj) == tuple) and (len(obj) > 0) and \ + if (isinstance(obj, tuple) and (len(obj) > 0) and \ ('strip' in dir(obj[0])) and (obj[0].strip()): # Some notes may be None, from early databases. (text, format) = obj diff --git a/src/GrampsDbUtils/_ReadGedcom.py b/src/GrampsDbUtils/_ReadGedcom.py index ccb652f7b..2dd98198a 100644 --- a/src/GrampsDbUtils/_ReadGedcom.py +++ b/src/GrampsDbUtils/_ReadGedcom.py @@ -106,7 +106,7 @@ def import2(database, filename, callback, code_set, use_trans): Import the gedcom file. """ - assert(type(code_set) == str or type(code_set) == unicode) + assert(isinstance(code_set, basestring)) try: ifile = open(filename, "rU") diff --git a/src/ManagedWindow.py b/src/ManagedWindow.py index cf2d52630..e685d3284 100644 --- a/src/ManagedWindow.py +++ b/src/ManagedWindow.py @@ -138,7 +138,7 @@ class GrampsWindowManager: # starting with the given item. # Eventualy, every non-list item (leaf) will be reached # and the func(item,*args) will be called on that item. - if type(item) == list: + if isinstance(item, list): # If this item is a branch # close the children except for the first one for sub_item in item[1:]: @@ -198,7 +198,7 @@ class GrampsWindowManager: # Make sure we have a track parent_item = self.get_item_from_track(track) - assert type(parent_item) == list or track == [], \ + assert isinstance(parent_item, list) or track == [], \ "Gwm: add_item: Incorrect track - Is parent not a leaf?" # Prepare a new item, depending on whether it is branch or leaf @@ -220,7 +220,7 @@ class GrampsWindowManager: return new_track def call_back_factory(self, item): - if type(item) != list: + if not isinstance(item, list): def func(obj): if item.window_id and self.id2item.get(item.window_id): self.id2item[item.window_id].present() @@ -233,7 +233,7 @@ class GrampsWindowManager: return str(item.window_id) def display_menu_list(self, data, action_data, mlist): - if type(mlist) in (list, tuple): + if isinstance(mlist, (list, tuple)): i = mlist[0] idval = self.generate_id(i) data.write('' % idval) @@ -247,9 +247,9 @@ class GrampsWindowManager: action_data.append((idval, None, i.menu_label, None, None, self.call_back_factory(i))) - if (type(mlist) in (list, tuple)) and (len(mlist) > 1): + if isinstance(mlist, (list, tuple)) and (len(mlist) > 1): for i in mlist[1:]: - if type(i) == list: + if isinstance(i, list): self.display_menu_list(data, action_data, i) else: idval = self.generate_id(i) @@ -257,7 +257,7 @@ class GrampsWindowManager: % self.generate_id(i)) action_data.append((idval, None, i.menu_label, None, None, self.call_back_factory(i))) - if type(mlist) in (list, tuple): + if isinstance(mlist, (list, tuple)): data.write('') def build_windows_menu(self): diff --git a/src/Models/_ListCursor.py b/src/Models/_ListCursor.py index 4b7dd9d8f..427e1ee60 100644 --- a/src/Models/_ListCursor.py +++ b/src/Models/_ListCursor.py @@ -157,7 +157,7 @@ class ListCursor(object): automatically unpickle it. So this method provides a convenient way to unpickle the object. """ - if rec and type(rec[1]) == type(""): + if rec and isinstance(rec[1], str): tmp = [rec[0],None] tmp[1] = cPickle.loads(rec[1]) rec = tmp diff --git a/src/Models/_PathCursor.py b/src/Models/_PathCursor.py index f224a43f0..7bbcfdb3e 100644 --- a/src/Models/_PathCursor.py +++ b/src/Models/_PathCursor.py @@ -236,7 +236,7 @@ class PathCursor(object): automatically unpickle it. So this method provides a convenient way to unpickle the object. """ - if rec and type(rec[1]) == type(""): + if rec and isinstance(rec[1], str): tmp = [rec[0],None] tmp[1] = cPickle.loads(rec[1]) rec = tmp diff --git a/src/PluginUtils/_Options.py b/src/PluginUtils/_Options.py index 8afb59a6c..516a6c45b 100644 --- a/src/PluginUtils/_Options.py +++ b/src/PluginUtils/_Options.py @@ -199,7 +199,7 @@ class OptionListCollection: f.write('\n' % escape(module_name)) options = option_list.get_options() for option_name in options.keys(): - if type(options[option_name]) in (type(list()),type(tuple())): + if isinstance(options[option_name], (list, tuple)): f.write('