summaryrefslogtreecommitdiff
path: root/bench/is_types.py
diff options
context:
space:
mode:
authorGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 +0000
committerGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 +0000
commiteb7e67b1e6e7315a945edf79ebd2ec160ee85588 (patch)
treefff879b4f9676a72e16c0f7b4dd969f050038b4f /bench/is_types.py
parentd5d9fceff1591065e13c1fcd283468fb0a288a36 (diff)
downloadscons-eb7e67b1e6e7315a945edf79ebd2ec160ee85588.tar.gz
http://scons.tigris.org/issues/show_bug.cgi?id=2329
Applied a number of idiomatic changes. Uses of the 'sort()' method were converted into calls of 'sorted()' when possible and the sorted() expression was inserted into a subsequent statement whenever that made sense. The statement 'while 1:' was changed to 'while True:'. Names from the 'types' module (e.g., 'types.FooType') were converted to the equivalent build-in type (e.g., 'foo'). Comparisons between types were changed to use 'isinstance()'.
Diffstat (limited to 'bench/is_types.py')
-rw-r--r--bench/is_types.py79
1 files changed, 41 insertions, 38 deletions
diff --git a/bench/is_types.py b/bench/is_types.py
index f9f76770..9cc397e5 100644
--- a/bench/is_types.py
+++ b/bench/is_types.py
@@ -15,7 +15,7 @@ except ImportError:
# and modified slightly for use with SCons.
class UserString:
def __init__(self, seq):
- if type(seq) == type(''):
+ if isinstance(seq, str):
self.data = seq
elif isinstance(seq, UserString):
self.data = seq.data[:]
@@ -60,11 +60,14 @@ except ImportError:
__rmul__ = __mul__
InstanceType = types.InstanceType
-DictType = types.DictType
-ListType = types.ListType
-StringType = types.StringType
-if hasattr(types, 'UnicodeType'):
- UnicodeType = types.UnicodeType
+DictType = dict
+ListType = list
+StringType = str
+try: unicode
+except NameError:
+ UnicodeType = None
+else:
+ UnicodeType = unicode
# The original implementations, pretty straightforward checks for the
@@ -72,19 +75,19 @@ if hasattr(types, 'UnicodeType'):
# User* type.
def original_is_Dict(e):
- return type(e) is types.DictType or isinstance(e, UserDict)
+ return isinstance(e, dict) or isinstance(e, UserDict)
def original_is_List(e):
- return type(e) is types.ListType or isinstance(e, UserList)
+ return isinstance(e, list) or isinstance(e, UserList)
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def original_is_String(e):
- return type(e) is types.StringType \
- or type(e) is types.UnicodeType \
+ return isinstance(e, str) \
+ or isinstance(e, unicode) \
or isinstance(e, UserString)
else:
def original_is_String(e):
- return type(e) is types.StringType or isinstance(e, UserString)
+ return isinstance(e, str) or isinstance(e, UserString)
@@ -93,22 +96,22 @@ else:
# type.
def checkInstanceType_is_Dict(e):
- return type(e) is types.DictType or \
- (type(e) is types.InstanceType and isinstance(e, UserDict))
+ return isinstance(e, dict) or \
+ (isinstance(e, types.InstanceType) and isinstance(e, UserDict))
def checkInstanceType_is_List(e):
- return type(e) is types.ListType \
- or (type(e) is types.InstanceType and isinstance(e, UserList))
+ return isinstance(e, list) \
+ or (isinstance(e, types.InstanceType) and isinstance(e, UserList))
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def checkInstanceType_is_String(e):
- return type(e) is types.StringType \
- or type(e) is types.UnicodeType \
- or (type(e) is types.InstanceType and isinstance(e, UserString))
+ return isinstance(e, str) \
+ or isinstance(e, unicode) \
+ or (isinstance(e, types.InstanceType) and isinstance(e, UserString))
else:
def checkInstanceType_is_String(e):
- return type(e) is types.StringType \
- or (type(e) is types.InstanceType and isinstance(e, UserString))
+ return isinstance(e, str) \
+ or (isinstance(e, types.InstanceType) and isinstance(e, UserString))
@@ -117,24 +120,24 @@ else:
def cache_type_e_is_Dict(e):
t = type(e)
- return t is types.DictType or \
+ return t is dict or \
(t is types.InstanceType and isinstance(e, UserDict))
def cache_type_e_is_List(e):
t = type(e)
- return t is types.ListType \
+ return t is list \
or (t is types.InstanceType and isinstance(e, UserList))
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def cache_type_e_is_String(e):
t = type(e)
- return t is types.StringType \
- or t is types.UnicodeType \
+ return t is str \
+ or t is unicode \
or (t is types.InstanceType and isinstance(e, UserString))
else:
def cache_type_e_is_String(e):
t = type(e)
- return t is types.StringType \
+ return t is str \
or (t is types.InstanceType and isinstance(e, UserString))
@@ -153,7 +156,7 @@ def global_cache_type_e_is_List(e):
return t is ListType \
or (t is InstanceType and isinstance(e, UserList))
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def global_cache_type_e_is_String(e):
t = type(e)
return t is StringType \
@@ -171,18 +174,18 @@ else:
# to their corresponding underlying types.
instanceTypeMap = {
- UserDict : types.DictType,
- UserList : types.ListType,
- UserString : types.StringType,
+ UserDict : dict,
+ UserList : list,
+ UserString : str,
}
-if hasattr(types, 'UnicodeType'):
+if UnicodeType is not None:
def myType(obj):
t = type(obj)
if t is types.InstanceType:
t = instanceTypeMap.get(obj.__class__, t)
- elif t is types.UnicodeType:
- t = types.StringType
+ elif t is unicode:
+ t = str
return t
else:
def myType(obj):
@@ -192,13 +195,13 @@ else:
return t
def myType_is_Dict(e):
- return myType(e) is types.DictType
+ return myType(e) is dict
def myType_is_List(e):
- return myType(e) is types.ListType
+ return myType(e) is list
def myType_is_String(e):
- return myType(e) is types.StringType
+ return myType(e) is str