diff options
author | Stefan Zimmermann <zimmermann.code@gmail.com> | 2014-03-31 15:21:40 (GMT) |
---|---|---|
committer | Stefan Zimmermann <zimmermann.code@gmail.com> | 2014-03-31 15:21:40 (GMT) |
commit | 87b458d186fe0553b054b8eeb7d57c80e0a54f21 (patch) | |
tree | bbc61ec90d436c8b470eb70bf9c09ed552261ef7 | |
parent | fd24c4ea622e271936c2df2a5efa484cd351bd9c (diff) | |
download | SCons-87b458d186fe0553b054b8eeb7d57c80e0a54f21.zip SCons-87b458d186fe0553b054b8eeb7d57c80e0a54f21.tar.gz SCons-87b458d186fe0553b054b8eeb7d57c80e0a54f21.tar.bz2 |
More __cmp__ to __eq__ (and __lt__). Resolved some UnboundLocalErrors after except.
-rw-r--r-- | bin/SConsDoc.py | 6 | ||||
-rw-r--r-- | bin/scons-proc.py | 11 | ||||
-rw-r--r-- | src/engine/SCons/Action.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Builder.py | 11 | ||||
-rw-r--r-- | src/engine/SCons/BuilderTests.py | 22 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 8 | ||||
-rw-r--r-- | src/engine/SCons/Memoize.py | 6 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/ScannerTests.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/__init__.py | 6 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 6 | ||||
-rw-r--r-- | test/Scanner/generated.py | 4 |
11 files changed, 51 insertions, 35 deletions
diff --git a/bin/SConsDoc.py b/bin/SConsDoc.py index 80f41a5..72c0306 100644 --- a/bin/SConsDoc.py +++ b/bin/SConsDoc.py @@ -668,8 +668,10 @@ class Item(object): if name[0] == '_': name = name[1:] return name.lower() - def __cmp__(self, other): - return cmp(self.sort_name, other.sort_name) + def __eq__(self, other): + return self.sort_name == other.sort_name + def __lt__(self, other): + return self.sort_name < other.sort_name class Builder(Item): pass diff --git a/bin/scons-proc.py b/bin/scons-proc.py index b93b25a..138cff7 100644 --- a/bin/scons-proc.py +++ b/bin/scons-proc.py @@ -231,10 +231,15 @@ class Proxy(object): """Retrieve the entire wrapped object""" return self.__subject - def __cmp__(self, other): + def __eq__(self, other): if issubclass(other.__class__, self.__subject.__class__): - return cmp(self.__subject, other) - return cmp(self.__dict__, other.__dict__) + return self.__subject == other + return self.__dict__ == other.__dict__ + + ## def __lt__(self, other): + ## if issubclass(other.__class__, self.__subject.__class__): + ## return self.__subject < other + ## return self.__dict__ < other.__dict__ class SConsThing(Proxy): def idfunc(self): diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 006e8f5..49b9f35 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -420,8 +420,8 @@ class ActionBase(object): other objects (Builders, Executors, etc.) This provides the common methods for manipulating and combining those actions.""" - def __cmp__(self, other): - return cmp(self.__dict__, other) + def __eq__(self, other): + return self.__dict__ == other def no_batch_key(self, env, target, source): return None diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 0f7aff4..4b41827 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -345,8 +345,11 @@ class EmitterProxy(object): return (target, source) - def __cmp__(self, other): - return cmp(self.var, other.var) + def __eq__(self, other): + return self.var == other.var + + def __lt__(self, other): + return self.var < other.var class BuilderBase(object): """Base class for Builders, objects that create output @@ -449,8 +452,8 @@ class BuilderBase(object): except AttributeError: return str(self.__class__) - def __cmp__(self, other): - return cmp(self.__dict__, other.__dict__) + def __eq__(self, other): + return self.__dict__ == other.__dict__ def splitext(self, path, env=None): if not env: diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 41b640b..eb56299 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -145,8 +145,8 @@ class Environment(object): d['SOURCES'] = ['__s1__', '__s2__', '__s3__', '__s4__', '__s5__', '__s6__'] d['SOURCE'] = d['SOURCES'][0] return d - def __cmp__(self, other): - return cmp(self.scanner, other.scanner) or cmp(self.d, other.d) + def __eq__(self, other): + return self.scanner == other.scanner or self.d == other.d class MyAction(object): def __init__(self, action): @@ -1500,9 +1500,10 @@ class CompositeBuilderTestCase(unittest.TestCase): builder(env, target='test3', source=['test2.bar', 'test1.foo'])[0] except SCons.Errors.UserError as e: flag = 1 + err = e assert flag, "UserError should be thrown when we call a builder with files of different suffixes." expect = "While building `['test3']' from `test1.foo': Cannot build multiple sources with different extensions: .bar, .foo" - assert str(e) == expect, e + assert str(err) == expect, err def test_source_ext_match(self): """Test the CompositeBuilder source_ext_match argument""" @@ -1584,45 +1585,50 @@ class CompositeBuilderTestCase(unittest.TestCase): builder(env, target='t5', source=['test5a.foo', 'test5b.inb'])[0] except SCons.Errors.UserError as e: flag = 1 + err = e assert flag, "UserError should be thrown when we call a builder with files of different suffixes." expect = "While building `['t5']' from `test5b.bar': Cannot build multiple sources with different extensions: .foo, .bar" - assert str(e) == expect, e + assert str(err) == expect, err flag = 0 try: builder(env, target='t6', source=['test6a.bar', 'test6b.ina'])[0] except SCons.Errors.UserError as e: flag = 1 + err = e assert flag, "UserError should be thrown when we call a builder with files of different suffixes." expect = "While building `['t6']' from `test6b.foo': Cannot build multiple sources with different extensions: .bar, .foo" - assert str(e) == expect, e + assert str(err) == expect, err flag = 0 try: builder(env, target='t4', source=['test4a.ina', 'test4b.inb'])[0] except SCons.Errors.UserError as e: flag = 1 + err = e assert flag, "UserError should be thrown when we call a builder with files of different suffixes." expect = "While building `['t4']' from `test4b.bar': Cannot build multiple sources with different extensions: .foo, .bar" - assert str(e) == expect, e + assert str(err) == expect, err flag = 0 try: builder(env, target='t7', source=[env.fs.File('test7')])[0] except SCons.Errors.UserError as e: flag = 1 + err = e assert flag, "UserError should be thrown when we call a builder with files of different suffixes." expect = "While building `['t7']': Cannot deduce file extension from source files: ['test7']" - assert str(e) == expect, e + assert str(err) == expect, err flag = 0 try: builder(env, target='t8', source=['test8.unknown'])[0] except SCons.Errors.UserError as e: flag = 1 + err = e assert flag, "UserError should be thrown when we call a builder target with an unknown suffix." expect = "While building `['t8']' from `['test8.unknown']': Don't know how to build from a source file with suffix `.unknown'. Expected a suffix in this list: ['.foo', '.bar']." - assert str(e) == expect, e + assert str(err) == expect, err if __name__ == "__main__": suite = unittest.TestSuite() diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 22552b3..6933b6b 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -113,11 +113,11 @@ class Scanner(object): global scanned_it scanned_it[filename] = 1 - def __cmp__(self, other): + def __eq__(self, other): try: - return cmp(self.__dict__, other.__dict__) + return self.__dict__ == other.__dict__ except AttributeError: - return 1 + return False def get_skeys(self, env): return self.skeys @@ -1613,7 +1613,7 @@ def exists(env): self.name = name def __str__(self): return self.name - def __cmp__(self, other): + def __eq__(self, other): raise Exception("should not compare") ccc = C('ccc') diff --git a/src/engine/SCons/Memoize.py b/src/engine/SCons/Memoize.py index ac728c9..d2938c7 100644 --- a/src/engine/SCons/Memoize.py +++ b/src/engine/SCons/Memoize.py @@ -145,11 +145,11 @@ class Counter(object): def display(self): fmt = " %7d hits %7d misses %s()" print(fmt % (self.hit, self.miss, self.name)) - def __cmp__(self, other): + def __eq__(self, other): try: - return cmp(self.name, other.name) + return self.name == other.name except AttributeError: - return 0 + return True class CountValue(Counter): """ diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index ee26922..f29d545 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -234,7 +234,7 @@ class BaseTestCase(unittest.TestCase): def test___cmp__(self): """Test the Scanner.Base class __cmp__() method""" s = SCons.Scanner.Base(self.func, "Cmp") - assert cmp(s, None) + assert s != None def test_hash(self): """Test the Scanner.Base class __hash__() method""" diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 2375bc4..5700fe9 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -221,12 +221,12 @@ class Base(object): nodes.append(l) return nodes - def __cmp__(self, other): + def __eq__(self, other): try: - return cmp(self.__dict__, other.__dict__) + return self.__dict__ == other.__dict__ except AttributeError: # other probably doesn't have a __dict__ - return cmp(self.__dict__, other) + return self.__dict__ == other def __hash__(self): return id(self) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 60e5c10..7ea2789 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -537,10 +537,10 @@ class Proxy(object): """Retrieve the entire wrapped object""" return self._subject - def __cmp__(self, other): + def __eq__(self, other): if issubclass(other.__class__, self._subject.__class__): - return cmp(self._subject, other) - return cmp(self.__dict__, other.__dict__) + return self._subject == other + return self.__dict__ == other.__dict__ class Delegate(object): """A Python Descriptor class that delegates attribute fetches diff --git a/test/Scanner/generated.py b/test/Scanner/generated.py index 845111c..82206c2 100644 --- a/test/Scanner/generated.py +++ b/test/Scanner/generated.py @@ -317,8 +317,8 @@ def write_out(file, dict): class CScannerCounter(object): def __init__(self, original_CScanner, *args, **kw): self.original_CScanner = original_CScanner - def __cmp__(self, *args, **kw): - return self.original_CScanner.__cmp__(*args, **kw) + def __eq__(self, *args, **kw): + return self.original_CScanner.__eq__(*args, **kw) def __hash__(self, *args, **kw): return self.original_CScanner.__hash__(*args, **kw) def __str__(self, *args, **kw): |