[py-svn] r33647 - in py/dist/py/apigen/tracer: . testing

fijal at codespeak.net fijal at codespeak.net
Tue Oct 24 13:10:46 CEST 2006


Author: fijal
Date: Tue Oct 24 13:10:44 2006
New Revision: 33647

Modified:
   py/dist/py/apigen/tracer/model.py
   py/dist/py/apigen/tracer/testing/test_model.py
Log:
Fixed anyof to use set (which is not py2.2 friendly).


Modified: py/dist/py/apigen/tracer/model.py
==============================================================================
--- py/dist/py/apigen/tracer/model.py	(original)
+++ py/dist/py/apigen/tracer/model.py	Tue Oct 24 13:10:44 2006
@@ -39,23 +39,16 @@
 class SomeUnion(object):
     # empty typedef
     def __init__(self, possibilities):
-        self.possibilities = possibilities
+        self.possibilities = set(possibilities)
     
     def unionof(self, other):
+        print self.possibilities
         if isinstance(other, SomeUnion):
-            poss = []
-            our_poss = {}
-            for p in self.possibilities:
-                our_poss[p] = True
-            for p in other.possibilities:
-                if not p in our_poss:
-                    poss.append(p)
-            poss += self.possibilities
-            return SomeUnion(poss)
-        return SomeUnion(self.possibilities + [other])
+            return SomeUnion(self.possibilities.union(other.possibilities))
+        return SomeUnion(list(self.possibilities) + [other])
     
     def __repr__(self):
-        return "AnyOf(%s)" % ",".join([str(i) for i in self.possibilities])
+        return "AnyOf(%s)" % ",".join([str(i) for i in list(self.possibilities)])
     
     def gettypedef(self):
         return (None, None)

Modified: py/dist/py/apigen/tracer/testing/test_model.py
==============================================================================
--- py/dist/py/apigen/tracer/testing/test_model.py	(original)
+++ py/dist/py/apigen/tracer/testing/test_model.py	Tue Oct 24 13:10:44 2006
@@ -57,6 +57,9 @@
         for i in a.possibilities:
             assert not isinstance(i, SomeUnion)
         return a
+        
+    class C(object):
+        pass
     
     ret = check_lst([3, 4, 3., "aa"])
     assert len(ret.possibilities) == 3
@@ -64,6 +67,13 @@
     ret2 = check_lst([1, "aa"])
     ret3 = unionof(ret, ret2)
     assert len(ret3.possibilities) == 3
+    ret = check_lst([3, 1.])
+    ret = unionof(ret, guess_type("aa"))
+    ret = unionof(guess_type("aa"), ret)
+    ret = unionof(guess_type(C()), ret)
+    ret = unionof(ret, guess_type("aa"))
+    ret = unionof(ret, guess_type(C()))
+    assert len(ret.possibilities) == 4
 
 def test_union():
     py.test.skip("We're not thinking about type unions right now")


More information about the py-svn mailing list