[pypy-svn] pypy fast-forward: 2.7 now allows complex('inf') and complex('1e500')

amauryfa commits-noreply at bitbucket.org
Mon Jan 3 03:11:58 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: fast-forward
Changeset: r40332:f252cc3fbadc
Date: 2011-01-03 03:13 +0100
http://bitbucket.org/pypy/pypy/changeset/f252cc3fbadc/

Log:	2.7 now allows complex('inf') and complex('1e500')

diff --git a/pypy/objspace/std/test/test_complexobject.py b/pypy/objspace/std/test/test_complexobject.py
--- a/pypy/objspace/std/test/test_complexobject.py
+++ b/pypy/objspace/std/test/test_complexobject.py
@@ -330,9 +330,10 @@
         assert x.foo == 42
         assert type(complex(x)) == complex
     
-    def test_overflow(self):
-        h = self.helper
-        raises(ValueError, complex, unicode("1"*500))
+    def test_infinity(self):
+        inf = 1e200*1e200
+        assert complex("1"*500) == complex(inf)
+        assert complex("-inf") == complex(-inf)
         
     def test_repr(self):
         assert repr(1+6j) == '(1+6j)'

diff --git a/pypy/objspace/std/complextype.py b/pypy/objspace/std/complextype.py
--- a/pypy/objspace/std/complextype.py
+++ b/pypy/objspace/std/complextype.py
@@ -11,9 +11,6 @@
 ERR_WRONG_SECOND = "complex() can't take second arg if first is a string"
 ERR_MALFORMED = "complex() arg is a malformed string"
 
-OVERFLOWED_FLOAT = 1e200
-OVERFLOWED_FLOAT *= OVERFLOWED_FLOAT
-
 complex_conjugate = StdObjSpaceMultiMethod('conjugate', 1,
                                            doc="(A+Bj).conjugate() -> A-Bj")
 
@@ -139,12 +136,6 @@
             imagval = string_to_float(imagstr)
         except ParseStringError:
             raise OperationError(space.w_ValueError, space.wrap(ERR_MALFORMED))
-        else:
-            # check for overflow
-            if (abs(realval) == OVERFLOWED_FLOAT or
-                abs(imagval) == OVERFLOWED_FLOAT):
-                raise OperationError(space.w_ValueError,space.wrap(
-                                    "complex() literal too large to convert"))
 
     else:
         # non-string arguments


More information about the Pypy-commit mailing list