[pypy-svn] r7519 - in pypy/trunk/src/pypy: objspace/flow translator/test

hpk at codespeak.net hpk at codespeak.net
Sat Nov 20 17:28:27 CET 2004


Author: hpk
Date: Sat Nov 20 17:28:26 2004
New Revision: 7519

Modified:
   pypy/trunk/src/pypy/objspace/flow/objspace.py
   pypy/trunk/src/pypy/translator/test/snippet.py
   pypy/trunk/src/pypy/translator/test/test_annrpython.py
Log:

allow tuple assignment/unpacking to retain type
information by special casing unpackiterable 
to treat the case where it receives a Constant 
and has to return an expected_length number of
items ... 



Modified: pypy/trunk/src/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/objspace.py	Sat Nov 20 17:28:26 2004
@@ -171,6 +171,10 @@
                 items.append(w_item)
                 i += 1
             return items
+        elif isinstance(w_iterable, Constant) and expected_length is not None: 
+            assert len(w_iterable.value) == expected_length 
+            return [self.do_operation('getitem', w_iterable, self.wrap(i)) 
+                        for i in range(expected_length)]
             # XXX TEMPORARY HACK XXX TEMPORARY HACK XXX TEMPORARY HACK
         return ObjSpace.unpackiterable(self, w_iterable, expected_length)
 

Modified: pypy/trunk/src/pypy/translator/test/snippet.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/snippet.py	(original)
+++ pypy/trunk/src/pypy/translator/test/snippet.py	Sat Nov 20 17:28:26 2004
@@ -583,3 +583,7 @@
 def funccallsex():
     return func_producing_exception()
 
+
+def func_arg_unpack():
+    a,b = 3, "hello"
+    return a

Modified: pypy/trunk/src/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/trunk/src/pypy/translator/test/test_annrpython.py	Sat Nov 20 17:28:26 2004
@@ -325,6 +325,12 @@
         # but let's at least check *something*
         #self.assert_(isinstance(s, SomeCallable))
 
+    def test_tuple_unpack_from_const_tuple_with_different_types(self):
+        a = RPythonAnnotator()
+        s = a.build_types(snippet.func_arg_unpack, [])
+        self.assert_(isinstance(s, annmodel.SomeInteger)) 
+        self.assertEquals(s.const, 3) 
+
 def g(n):
     return [0,1,2,n]
 



More information about the Pypy-commit mailing list