[pypy-svn] r45964 - in pypy/branch/pypy-more-rtti-inprogress: annotation rpython/test

arigo at codespeak.net arigo at codespeak.net
Fri Aug 24 18:59:55 CEST 2007


Author: arigo
Date: Fri Aug 24 18:59:54 2007
New Revision: 45964

Modified:
   pypy/branch/pypy-more-rtti-inprogress/annotation/binaryop.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_rfloat.py
Log:
Test and fix: float division doesn't raise ZeroDivisionError in RPython.


Modified: pypy/branch/pypy-more-rtti-inprogress/annotation/binaryop.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/annotation/binaryop.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/annotation/binaryop.py	Fri Aug 24 18:59:54 2007
@@ -419,11 +419,21 @@
     def union((flt1, flt2)):
         return SomeFloat()
 
-    add = sub = mul = div = truediv = union
+    add = sub = mul = union
+
+    def div((flt1, flt2)):
+        return SomeFloat()
+    div.can_only_throw = []
+    truediv = div
 
     def pow((flt1, flt2), obj3):
         return SomeFloat()
-    pow.can_only_throw = [ZeroDivisionError, ValueError, OverflowError]    
+    pow.can_only_throw = [ZeroDivisionError, ValueError, OverflowError]
+
+    # repeat these in order to copy the 'can_only_throw' attribute
+    inplace_div = div
+    inplace_truediv = truediv
+    inplace_pow = pow
 
 
 class __extend__(pairtype(SomeList, SomeList)):

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_rfloat.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_rfloat.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_rfloat.py	Fri Aug 24 18:59:54 2007
@@ -108,6 +108,16 @@
         res = self.interpret(fn, [2.0, 3.0])
         assert res == 8.0
 
+    def test_exceptions(self):
+        def fn(x, y, z):
+            try:
+                # '/', when float-based, cannot raise in RPython!
+                # the try:finally: only tests an annotation bug.
+                x /= (y / z)
+            finally:
+                return x
+        self.interpret(fn, [1.0, 2.0, 3.0])
+
 class TestLLtype(BaseTestRfloat, LLRtypeMixin):
 
     def test_hash(self):



More information about the Pypy-commit mailing list