summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Util.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-05-19 16:41:32 (GMT)
committerSteven Knight <knight@baldmt.com>2010-05-19 16:41:32 (GMT)
commit093701db6b7b705bc0f73afc6c933a32c4df100a (patch)
tree4407cabad6f5c89ba64993a38e4c4d1733e9c2e5 /src/engine/SCons/Util.py
parent435a720015d6950aac38096509290d7577b08688 (diff)
downloadSCons-093701db6b7b705bc0f73afc6c933a32c4df100a.zip
SCons-093701db6b7b705bc0f73afc6c933a32c4df100a.tar.gz
SCons-093701db6b7b705bc0f73afc6c933a32c4df100a.tar.bz2
Convert SubstitutionEnvironment from an old-style class to a new-style class.
Diffstat (limited to 'src/engine/SCons/Util.py')
-rw-r--r--src/engine/SCons/Util.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index 54e738f..bd653ec 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -1356,7 +1356,7 @@ def make_path_relative(path):
# ASPN: Python Cookbook : Dynamically added methods to a class
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81732
-def AddMethod(object, function, name = None):
+def AddMethod(obj, function, name=None):
"""
Adds either a bound method to an instance or an unbound method to
a class. If name is ommited the name of the specified function
@@ -1376,14 +1376,12 @@ def AddMethod(object, function, name = None):
else:
function = RenameFunction(function, name)
- try:
- klass = object.__class__
- except AttributeError:
- # "object" is really a class, so it gets an unbound method.
- object.__dict__[name] = types.MethodType(function, None, object)
+ if hasattr(obj, '__class__') and obj.__class__ != types.TypeType:
+ # "obj" is an instance, so it gets a bound method.
+ setattr(obj, name, types.MethodType(function, obj, cls))
else:
- # "object" is really an instance, so it gets a bound method.
- object.__dict__[name] = types.MethodType(function, object, klass)
+ # "obj" is a class, so it gets an unbound method.
+ setattr(obj, name, types.MethodType(function, None, obj))
def RenameFunction(function, name):
"""