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

ac at codespeak.net ac at codespeak.net
Thu Sep 8 16:26:20 CEST 2005


Author: ac
Date: Thu Sep  8 16:26:20 2005
New Revision: 17369

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
Fix bug when mixing constant list/dict with None.

Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Thu Sep  8 16:26:20 2005
@@ -577,7 +577,7 @@
 class __extend__(pairtype(SomeList, SomePBC)):
     def union((lst, pbc)):
         if pbc.isNone():
-            return lst
+            return SomeList(lst.listdef)
         return SomeObject()
 
 class __extend__(pairtype(SomePBC, SomeList    )):
@@ -588,7 +588,7 @@
 class __extend__(pairtype(SomeDict, SomePBC)):
     def union((dct, pbc)):
         if pbc.isNone():
-            return dct
+            return SomeDict(dct.dictdef)
         return SomeObject()
 
 class __extend__(pairtype(SomePBC, SomeDict    )):

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	Thu Sep  8 16:26:20 2005
@@ -1533,6 +1533,30 @@
         a = self.RPythonAnnotator()
         s = a.build_types(f, [int])
         assert s.knowntype == dict
+
+    def test_const_list_and_none(self):
+        def g(l=None):
+            return l is None
+        L = [1,2]
+        def f():
+            g()
+            return g(L)
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [])
+        assert s.knowntype == bool
+        assert not s.is_constant()
+            
+    def test_const_dict_and_none(self):
+        def g(d=None):
+            return d is None
+        D = {1:2}
+        def f():
+            g(D)
+            return g()
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [])
+        assert s.knowntype == bool
+        assert not s.is_constant()
                         
 
 def g(n):



More information about the Pypy-commit mailing list