[pypy-svn] r17287 - in pypy/dist/pypy: annotation translator/test

pedronis at codespeak.net pedronis at codespeak.net
Tue Sep 6 15:15:17 CEST 2005


Author: pedronis
Date: Tue Sep  6 15:15:16 2005
New Revision: 17287

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
support mixing dicts and None (in annotation)



Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Tue Sep  6 15:15:16 2005
@@ -584,6 +584,17 @@
     def union((pbc, lst)):
         return pair(lst, pbc).union()
 
+# let mix dicts and None
+class __extend__(pairtype(SomeDict, SomePBC)):
+    def union((dct, pbc)):
+        if pbc.isNone():
+            return dct
+        return SomeObject()
+
+class __extend__(pairtype(SomePBC, SomeDict    )):
+    def union((pbc, dct)):
+        return pair(dct, pbc).union()
+
 # mixing strings and None
 
 class __extend__(pairtype(SomeString, SomePBC)):

Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py	Tue Sep  6 15:15:16 2005
@@ -1524,6 +1524,17 @@
         assert s.items[0].can_be_None
         assert s.items[1] == a.bookkeeper.immutablevalue(A.hello)
 
+    def test_dict_and_none(self):
+        def f(i):
+            if i:
+                return {}
+            else:
+                return None
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int])
+        assert s.knowntype == dict
+                        
+
 def g(n):
     return [0,1,2,n]
 



More information about the Pypy-commit mailing list