Issue #0002175: Change type() expressions to isinstance() expressions.

Patch from Gerald Britton <gerald.britton@gmail.com>


svn: r10762
This commit is contained in:
Zsolt Foldvari
2008-05-25 19:55:47 +00:00
parent 62b6250d2f
commit 998908175f
53 changed files with 105 additions and 113 deletions

View File

@@ -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):

View File

@@ -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())

View File

@@ -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:

View File

@@ -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

View File

@@ -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)