Commits

Stefan Zimmermann committed cfaeb72

More __cmp__ to __eq__ (and __lt__). Resolved some UnboundLocalErrors after except.

Comments (0)

Files changed (11)

         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

bin/scons-proc.py

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

src/engine/SCons/Action.py

     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

src/engine/SCons/Builder.py

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

src/engine/SCons/BuilderTests.py

         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):
             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"""
             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()

src/engine/SCons/EnvironmentTests.py

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

src/engine/SCons/Memoize.py

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

src/engine/SCons/Scanner/ScannerTests.py

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

src/engine/SCons/Scanner/__init__.py

             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)

src/engine/SCons/Util.py

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

test/Scanner/generated.py

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