[pypy-dev] Annotating space status

Samuele Pedroni pedronis at bluewin.ch
Tue Jul 1 22:17:10 CEST 2003


At 07:54 01.07.2003 -0400, Guido van Rossum wrote:
>I'm hoping Armin has some time to look into this; I probably won't.
>
>There's this test that doesn't work any more:
>
>     def dont_test_assign_local_w_flow_control(self):
>         # XXX This test doesn't work any more -- disabled for now
>         code = """
>def f(n):
>     total = 0
>     for i in range(n):
>         total = total + 1
>     return n
>"""
>         x = self.codetest(code, 'f', [self.space.wrap(3)])
>         self.assertEquals(type(x), W_Integer)

'self.assertEquals(type(x), W_Integer)' should be

'self.assertEquals(type(x), W_Constant)'

or we should have a 'return total' instead of 'return n'

>It worked before, when range(n) was enough to befuddle the symbolic
>interpretation, but now, when you enable it (remove the "dont_" from
>the name) it raises "TypeError: no result at all?!?!"
>
>This seems to be because the next() call implicit in the for loop
>doesn't ever raise IndeterminateCondition, because it is iterating
>over a constant list (the list [0, 1, 2] returned by range(3)).  But
>somehome frame unification decides to unify states after the 2nd time
>through the loop -- and the alternative branch (to the end of the
>loop) is never taken, so there is never a return value.
>
>What's wrong here???

this should fix it:

Index: pypy/objspace/ann/objspace.py
===================================================================
--- pypy/objspace/ann/objspace.py       (revision 1076)
+++ pypy/objspace/ann/objspace.py       (working copy)
@@ -285,16 +285,16 @@
              force = w_iterator.force
              w_iterator.force = None
              if force:
+                if isinstance(w_iterator, W_ConstantIterator):
+                    try:
+                        value = w_iterator.next()
+                    except StopIteration:
+                        raise NoValue # XXX could be also ExitFrame?
+                    else:
+                        return self.wrap(value)
                  return W_Anything()
              else:
                  raise NoValue
-        if isinstance(w_iterator, W_ConstantIterator):
-            try:
-                value = w_iterator.next()
-            except StopIteration:
-                raise NoValue
-            else:
-                return self.wrap(value)
          raise IndeterminateCondition(w_iterator)

      def call(self, w_func, w_args, w_kwds):



More information about the Pypy-dev mailing list