Issue #0002175: Change type() expressions to isinstance() expressions.
Patch from Gerald Britton <gerald.britton@gmail.com> svn: r10762
This commit is contained in:
parent
62b6250d2f
commit
998908175f
@ -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:
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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:
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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] = []
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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('<menu action="M:%s">' % 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('</menu>')
|
||||
|
||||
def build_windows_menu(self):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -199,7 +199,7 @@ class OptionListCollection:
|
||||
f.write('<module name="%s">\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(' <option name="%s" value="" length="%d">\n' % (
|
||||
escape(option_name),
|
||||
len(options[option_name]) ) )
|
||||
|
@ -88,9 +88,9 @@ class Tool:
|
||||
if issubclass(options_class, MenuToolOptions):
|
||||
# FIXME: pass in person_id
|
||||
self.options = options_class(name, None, dbstate)
|
||||
elif type(options_class) == ClassType:
|
||||
elif isinstance(options_class, ClassType):
|
||||
self.options = options_class(name)
|
||||
elif type(options_class) == InstanceType:
|
||||
elif isinstance(options_class, InstanceType):
|
||||
self.options = options_class
|
||||
self.options.load_previous_values()
|
||||
|
||||
@ -219,7 +219,7 @@ class CommandLineTool:
|
||||
self.options_help[self.show][1])
|
||||
print " Available values are:"
|
||||
vals = self.options_help[self.show][2]
|
||||
if type(vals) in [list,tuple]:
|
||||
if isinstance(vals, (list, tuple)):
|
||||
if self.options_help[self.show][3]:
|
||||
for num in range(len(vals)):
|
||||
print " %d\t%s" % (num,vals[num])
|
||||
|
@ -157,7 +157,7 @@ def run_report(dbstate, uistate, category, handle, func, **kwargs):
|
||||
d = TextBufDoc(make_basic_stylesheet(), None, None)
|
||||
d.dbstate = dbstate
|
||||
d.uistate = uistate
|
||||
if type(handle) in [str, unicode]: # a handle
|
||||
if isinstance(handle, basestring): # a handle
|
||||
if category == CATEGORY_QR_PERSON :
|
||||
obj = dbstate.db.get_person_from_handle(handle)
|
||||
elif category == CATEGORY_QR_FAMILY :
|
||||
|
@ -353,7 +353,7 @@ class CommandLineReport:
|
||||
self.options_help[self.show][1])
|
||||
print " Available values are:"
|
||||
vals = self.options_help[self.show][2]
|
||||
if type(vals) in [list,tuple]:
|
||||
if isinstance(vals, (list, tuple)):
|
||||
if self.options_help[self.show][3]:
|
||||
for num in range(len(vals)):
|
||||
print " %d\t%s" % (num,vals[num])
|
||||
|
@ -805,10 +805,10 @@ class GraphvizReportDialog(ReportDialog):
|
||||
name, translated_name)
|
||||
|
||||
def init_options(self, option_class):
|
||||
if type(option_class) == ClassType:
|
||||
if isinstance(option_class, ClassType):
|
||||
self.options = option_class(self.raw_name,
|
||||
self.dbstate.get_database())
|
||||
elif type(option_class) == InstanceType:
|
||||
elif isinstance(option_class, InstanceType):
|
||||
self.options = option_class
|
||||
|
||||
################################
|
||||
|
@ -96,9 +96,9 @@ class ReportDialog(ManagedWindow.ManagedWindow):
|
||||
self.init_interface()
|
||||
|
||||
def init_options(self, option_class):
|
||||
if type(option_class) == ClassType:
|
||||
if isinstance(option_class, ClassType):
|
||||
self.options = option_class(self.raw_name, self.db)
|
||||
elif type(option_class) == InstanceType:
|
||||
elif isinstance(option_class, InstanceType):
|
||||
self.options = option_class
|
||||
|
||||
self.options.load_previous_values()
|
||||
|
@ -1528,7 +1528,7 @@ def estimate_age_on_date(db, person, ddata=_TODAY):
|
||||
#-------------------------------------------------------------------------
|
||||
def roman(num):
|
||||
""" Integer to Roman numeral converter for 0 < num < 4000 """
|
||||
if type(num) != int:
|
||||
if not isinstance(num, int):
|
||||
return "?"
|
||||
if not 0 < num < 4000:
|
||||
return "?"
|
||||
|
@ -612,7 +612,7 @@ class SimpleAccess:
|
||||
@rtype: list
|
||||
"""
|
||||
assert(isinstance(obj, (gen.lib.Person, gen.lib.Family, NoneType)))
|
||||
assert(type(restrict) == type([]) or restrict == None)
|
||||
assert(isinstance(restrict, list) or restrict == None)
|
||||
|
||||
if obj:
|
||||
event_handles = [ ref.ref for ref in obj.get_event_ref_list() ]
|
||||
|
@ -179,9 +179,9 @@ class SimpleTable:
|
||||
for col in range(len(data)):
|
||||
item = data[col]
|
||||
# FIXME: add better text representations of these objects
|
||||
if type(item) in [str, unicode]:
|
||||
if isinstance(item, basestring):
|
||||
retval.append(item)
|
||||
elif type(item) in [int, float, long]:
|
||||
elif isinstance(item, (int, float, long)):
|
||||
retval.append(item)
|
||||
self.row_sort_val(col, item)
|
||||
elif isinstance(item, gen.lib.Person):
|
||||
|
@ -193,7 +193,7 @@ class TreeTips(gtk.Widget):
|
||||
tip = model.get_value(rowIter, self.column)
|
||||
# The tip can be either a string or
|
||||
# a function that returns a string.
|
||||
if type(tip) == str:
|
||||
if isinstance(tip, str):
|
||||
text = tip
|
||||
elif callable(tip):
|
||||
text = tip()
|
||||
|
@ -124,7 +124,7 @@ data_recover_msg = _('The data can only be recovered by Undo operation '
|
||||
'or by quitting with abandoning changes.')
|
||||
|
||||
def fix_encoding(value):
|
||||
if type(value) != unicode:
|
||||
if not isinstance(value, unicode):
|
||||
try:
|
||||
return unicode(value)
|
||||
except:
|
||||
@ -150,7 +150,7 @@ def xml_lang():
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
def force_unicode(n):
|
||||
if type(n) != unicode:
|
||||
if not isinstance(n, unicode):
|
||||
return (unicode(n).lower(), unicode(n))
|
||||
else:
|
||||
return (n.lower(), n)
|
||||
|
@ -76,7 +76,7 @@ class AttributeBase:
|
||||
@param attribute: L{Attribute} instance to add.
|
||||
@type attribute: L{Attribute}
|
||||
"""
|
||||
assert type(attribute) != unicode
|
||||
assert not isinstance(attribute, unicode)
|
||||
self.attribute_list.append(attribute)
|
||||
|
||||
def remove_attribute(self, attribute):
|
||||
|
@ -192,7 +192,7 @@ class Date:
|
||||
if len(source) == 0:
|
||||
source = None
|
||||
elif len(source) == 1:
|
||||
if type(source[0]) == int:
|
||||
if isinstance(source[0], int):
|
||||
source = (source[0], 0, 0)
|
||||
else:
|
||||
source = source[0]
|
||||
@ -203,7 +203,7 @@ class Date:
|
||||
else:
|
||||
raise AttributeError, "invalid args to Date: %s" % source
|
||||
#### ok, process either date or tuple
|
||||
if type(source) == tuple:
|
||||
if isinstance(source, tuple):
|
||||
if calendar == None:
|
||||
self.calendar = Date.CAL_GREGORIAN
|
||||
else:
|
||||
@ -221,7 +221,7 @@ class Date:
|
||||
self.sortval = 0
|
||||
self.newyear = 0
|
||||
self.set_yr_mon_day(*source)
|
||||
elif type(source) == str and source != "":
|
||||
elif isinstance(source, str) and source != "":
|
||||
if (calendar != None or
|
||||
modifier != None or
|
||||
quality != None):
|
||||
@ -302,9 +302,9 @@ class Date:
|
||||
"""
|
||||
Date arithmetic: Date() + years, or Date() + (years, [months, [days]]).
|
||||
"""
|
||||
if type(other) == int:
|
||||
if isinstance(other, int):
|
||||
return self.copy_offset_ymd(other)
|
||||
elif type(other) in [tuple, list]:
|
||||
elif isinstance(other, (tuple, list)):
|
||||
return self.copy_offset_ymd(*other)
|
||||
else:
|
||||
raise AttributeError, "unknown date add type: %s " % type(other)
|
||||
@ -319,11 +319,11 @@ class Date:
|
||||
"""
|
||||
Date arithmetic: Date() - years, Date - (y,m,d), or Date() - Date().
|
||||
"""
|
||||
if type(other) == int: # Date - value -> Date
|
||||
if isinstance(other, int): # Date - value -> Date
|
||||
return self.copy_offset_ymd(-other)
|
||||
elif type(other) in [tuple, list]: # Date - (y, m, d) -> Date
|
||||
elif isinstance(other, (tuple, list)): # Date - (y, m, d) -> Date
|
||||
return self.copy_offset_ymd(*map(lambda x: -x, other))
|
||||
elif type(other) == type(self): # Date1 - Date2 -> tuple
|
||||
elif isinstance(other, self): # Date1 - Date2 -> tuple
|
||||
# We should make sure that Date2 + tuple -> Date1 and
|
||||
# Date1 - tuple -> Date2
|
||||
d1 = map(lambda i: i or 1, self.get_ymd())
|
||||
|
@ -134,13 +134,13 @@ class GrampsType(object):
|
||||
self.string = u''
|
||||
|
||||
def set(self, value):
|
||||
if type(value) == tuple:
|
||||
if isinstance(value, tuple):
|
||||
self.__set_tuple(value)
|
||||
elif type(value) == int:
|
||||
elif isinstance(value, int):
|
||||
self.__set_int(value)
|
||||
elif isinstance(value, self.__class__):
|
||||
self.__set_instance(value)
|
||||
elif type(value) in (str,unicode):
|
||||
elif isinstance(value, basestring):
|
||||
self.__set_str(value)
|
||||
else:
|
||||
self.val = self._DEFAULT
|
||||
@ -208,14 +208,14 @@ class GrampsType(object):
|
||||
return self._CUSTOM
|
||||
|
||||
def __cmp__(self, value):
|
||||
if type(value) == int:
|
||||
if isinstance(value, int):
|
||||
return cmp(self.val, value)
|
||||
elif type(value) in (str, unicode):
|
||||
elif isinstance(value, basestring):
|
||||
if self.val == self._CUSTOM:
|
||||
return cmp(self.string, value)
|
||||
else:
|
||||
return cmp(self._I2SMAP.get(self.val), value)
|
||||
elif type(value) == tuple:
|
||||
elif isinstance(value, tuple):
|
||||
return cmp((self.val, self.string), value)
|
||||
else:
|
||||
if value.val == self._CUSTOM:
|
||||
|
@ -71,17 +71,17 @@ class MarkerType(GrampsType):
|
||||
else:
|
||||
self.val = value.val
|
||||
self.string = value.string
|
||||
elif type(value) == tuple:
|
||||
elif isinstance(value, tuple):
|
||||
if value[0] == self.CUSTOM and value[1] == u'':
|
||||
self.value = self.NONE
|
||||
self.string = u''
|
||||
else:
|
||||
self.val = value[0]
|
||||
self.string = value[1]
|
||||
elif type(value) == int:
|
||||
elif isinstance(value, int):
|
||||
self.val = value
|
||||
self.string = u''
|
||||
elif type(value) == str:
|
||||
elif isinstance(value, str):
|
||||
self.val = self._S2IMAP.get(value, self._CUSTOM)
|
||||
if self.val == self._CUSTOM:
|
||||
self.string = value
|
||||
|
@ -709,7 +709,7 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase,
|
||||
Person's L{Family} list.
|
||||
@type family_handle: str
|
||||
"""
|
||||
if type(family_handle) not in (str, unicode):
|
||||
if not isinstance(family_handle, basestring):
|
||||
raise ValueError("expecting handle")
|
||||
if family_handle not in self.parent_family_list:
|
||||
self.parent_family_list.append(family_handle)
|
||||
|
@ -397,8 +397,8 @@ class Callback(object):
|
||||
for (key, fn) in self.__callback_map[signal_name]:
|
||||
self._log("Calling callback with key: %s\n" % (key, ))
|
||||
try:
|
||||
if type(fn) == types.FunctionType or \
|
||||
type(fn) == types.MethodType: # call func
|
||||
if isinstance(fn, types.FunctionType) or \
|
||||
isinstance(fn, types.MethodType): # call func
|
||||
fn(*args)
|
||||
else:
|
||||
self._warn("Badly formed entry in callback map.\n")
|
||||
|
@ -213,26 +213,26 @@ class TestCallback(unittest.TestCase):
|
||||
|
||||
t = TestSignals()
|
||||
t.connect('test-int',fn), t.emit('test-int',(1,))
|
||||
assert type(rl[0]) == int, "not int"
|
||||
assert isinstance(rl[0], int), "not int"
|
||||
|
||||
t.connect('test-list',fn), t.emit('test-list',([1,2],))
|
||||
assert type(rl[1]) == list, "not list"
|
||||
assert isinstance(rl[1], list), "not list"
|
||||
|
||||
t.connect('test-object',fn), t.emit('test-object',(t,))
|
||||
assert isinstance(rl[2], object), "not object"
|
||||
|
||||
t.connect('test-float',fn), t.emit('test-float',(2.3,))
|
||||
assert type(rl[3]) == float, "not float"
|
||||
assert isinstance(rl[3], float), "not float"
|
||||
|
||||
t.connect('test-dict',fn), t.emit('test-dict',({1:2},))
|
||||
assert type(rl[4]) == dict, "not dict"
|
||||
assert isinstance(rl[4], dict), "not dict"
|
||||
|
||||
rl = []
|
||||
def fn2(i,s,l, o,f,r=rl):
|
||||
rl.append(i)
|
||||
|
||||
t.connect('test-lots',fn2), t.emit('test-lots',(1,'a',[1,2],t,1.2))
|
||||
assert type(rl[0]) == int, "not lots"
|
||||
assert isinstance(rl[0], int), "not lots"
|
||||
|
||||
# This should fail because the type of arg1 is wrong
|
||||
res=[]
|
||||
|
@ -147,7 +147,7 @@ class GenChart:
|
||||
|
||||
def not_blank(self,line):
|
||||
for i in line:
|
||||
if i and type(i) == tuple:
|
||||
if i and isinstance(i, tuple):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@ -377,7 +377,7 @@ class AncestorTree(Report):
|
||||
for x in range(startx,stopx):
|
||||
value = self.genchart.get_xy(x,y)
|
||||
if value:
|
||||
if type(value) == tuple:
|
||||
if isinstance(value, tuple):
|
||||
(person,index) = value
|
||||
text = '\n'.join(self.text[index])
|
||||
self.doc.draw_box("AC2-box",
|
||||
@ -426,7 +426,7 @@ class AncestorTree(Report):
|
||||
value = self.genchart.get_xy(x,y)
|
||||
if not value:
|
||||
continue
|
||||
if type(value) == tuple:
|
||||
if isinstance(value, tuple):
|
||||
(person,index) = value
|
||||
if self.genchart.get(index*2):
|
||||
(px,py) = self.genchart.index_to_xy(index*2)
|
||||
|
@ -433,7 +433,7 @@ class BookList:
|
||||
options = item.option_class.handler.options_dict
|
||||
for option_name in options.keys():
|
||||
option_value = options[option_name]
|
||||
if type(option_value) in (type(list()), type(tuple())):
|
||||
if isinstance(option_value, (list, tuple)):
|
||||
f.write(' <option name="%s" value="" '
|
||||
'length="%d">\n' % (
|
||||
escape(option_name),
|
||||
|
@ -858,10 +858,10 @@ class Holidays:
|
||||
d = int(d)
|
||||
ndate = datetime.date(y, m, d)
|
||||
if self.debug: print ndate, offset, type(offset)
|
||||
if type(offset) == int:
|
||||
if isinstance(offset, int):
|
||||
if offset != 0:
|
||||
ndate = ndate.fromordinal(ndate.toordinal() + offset)
|
||||
elif type(offset) in [type(u''), str]:
|
||||
elif isinstance(offset, basestring):
|
||||
dir = 1
|
||||
if offset[0] == "-":
|
||||
dir = -1
|
||||
|
@ -326,13 +326,13 @@ class CheckIntegrity:
|
||||
|
||||
for handle in self.db.media_map.keys():
|
||||
data = self.db.media_map[handle]
|
||||
if type(data[2]) != unicode or type(data[4]) != unicode:
|
||||
if not isinstance(data[2], unicode) or not isinstance(data[4], unicode):
|
||||
obj = self.db.get_object_from_handle(handle)
|
||||
obj.path = Utils.fix_encoding( obj.path)
|
||||
obj.desc = Utils.fix_encoding( obj.desc)
|
||||
self.db.commit_media_object(obj,self.trans)
|
||||
# Once we are here, fix the mime string if not str
|
||||
if type(data[3]) != str:
|
||||
if not isinstance(data[3], str):
|
||||
obj = self.db.get_object_from_handle(handle)
|
||||
try:
|
||||
if data[3] == str(data[3]):
|
||||
@ -798,7 +798,7 @@ class CheckIntegrity:
|
||||
person.get_event_ref_list().remove(event_ref)
|
||||
self.db.commit_person(person,self.trans)
|
||||
self.invalid_events.append(key)
|
||||
elif type(person.get_event_ref_list()) != list:
|
||||
elif not isinstance(person.get_event_ref_list(), list):
|
||||
# event_list is None or other garbage
|
||||
person.set_event_ref_list([])
|
||||
self.db.commit_person(person,self.trans)
|
||||
@ -820,7 +820,7 @@ class CheckIntegrity:
|
||||
family.set_event_ref_list(nlist)
|
||||
self.db.commit_family(family,self.trans)
|
||||
self.invalid_events.append(key)
|
||||
elif type(family.get_event_ref_list()) != list:
|
||||
elif not isinstance(family.get_event_ref_list(), list):
|
||||
# event_list is None or other garbage
|
||||
family.set_event_ref_list([])
|
||||
self.db.commit_family(family,self.trans)
|
||||
|
@ -180,7 +180,7 @@ class CmdRef(Tool.Tool):
|
||||
% escape(oclass.options_help[arg][1]))
|
||||
|
||||
if len(oclass.options_help[arg])>2:
|
||||
if type(oclass.options_help[arg][2]) in [list,tuple]:
|
||||
if isinstance(oclass.options_help[arg][2], (list, tuple)):
|
||||
if oclass.options_help[arg][3]:
|
||||
f.write(' <orderedlist>\n')
|
||||
for val in oclass.options_help[arg][2]:
|
||||
|
@ -90,7 +90,7 @@ class GenChart:
|
||||
|
||||
def not_blank(self,line):
|
||||
for i in line:
|
||||
if i and type(i) == tuple:
|
||||
if i and isinstance(i, tuple):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@ -352,7 +352,7 @@ class DescendTree(Report):
|
||||
phys_x = 0
|
||||
for x in range(startx,stopx):
|
||||
value = self.genchart.get_xy(x,y)
|
||||
if type(value) == str or type(value) == unicode:
|
||||
if isinstance(value, basestring):
|
||||
text = '\n'.join(self.text[(x,y)])
|
||||
xbegin = phys_x*self.delta
|
||||
yend = phys_y*bh+self.offset
|
||||
|
@ -63,7 +63,7 @@ def run(database, document, person):
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
if type(person) == str:
|
||||
if isinstance(person, str):
|
||||
surname = person
|
||||
rsurname = person
|
||||
else:
|
||||
|
@ -1160,10 +1160,10 @@ class Holidays:
|
||||
d = int(d)
|
||||
ndate = datetime.date(y, m, d)
|
||||
if self.debug: print ndate, offset, type(offset)
|
||||
if type(offset) == int:
|
||||
if isinstance(offset, int):
|
||||
if offset != 0:
|
||||
ndate = ndate.fromordinal(ndate.toordinal() + offset)
|
||||
elif type(offset) in [type(u''), str]:
|
||||
elif isinstance(offset, basestring):
|
||||
dir = 1
|
||||
if offset[0] == "-":
|
||||
dir = -1
|
||||
|
@ -165,7 +165,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) in (str,unicode):
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -182,8 +182,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -271,8 +271,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -192,8 +192,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -301,8 +301,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -334,8 +334,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -242,8 +242,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -264,7 +264,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
#orig person, apperently secondRel in this function
|
||||
(secondRel,firstRel,common) = self.get_relationship_distance(orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -217,8 +217,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -165,8 +165,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||
(secondRel,firstRel,common) = \
|
||||
self.get_relationship_distance(db, orig_person, other_person)
|
||||
|
||||
if type(common) == types.StringType or \
|
||||
type(common) == types.UnicodeType:
|
||||
if isinstance(common, basestring):
|
||||
return (common,[])
|
||||
elif common:
|
||||
person_handle = common[0]
|
||||
|
@ -375,7 +375,7 @@ class MonitoredDataType:
|
||||
|
||||
def update(self):
|
||||
val = self.get_val()
|
||||
if type(val) == tuple :
|
||||
if isinstance(val, tuple):
|
||||
self.sel.set_values(val)
|
||||
else:
|
||||
self.sel.set_values((int(val), str(val)))
|
||||
|
Loading…
Reference in New Issue
Block a user