Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r58182:a3f4c69543dc
Date: 2012-10-17 18:55 +0200
http://bitbucket.org/pypy/pypy/changeset/a3f4c69543dc/

Log:    add one more edge case to complex parsing

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
@@ -29,9 +29,11 @@
     imagstop = 0
     imagsign = ' '
     i = 0
-    # ignore whitespace
+    # ignore whitespace at beginning and end
     while i < slen and s[i] == ' ':
         i += 1
+    while slen > 0 and s[slen-1] == ' ':
+        slen -= 1
 
     if s[i] == '(' and s[slen-1] == ')':
         i += 1
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
@@ -295,7 +295,7 @@
         assert self.almost_equal(complex(),  0)
         assert self.almost_equal(complex("-1"), -1)
         assert self.almost_equal(complex("+1"), +1)
-        assert self.almost_equal(complex(" ( +3.14-6J )"), 3.14-6j)
+        assert self.almost_equal(complex(" ( +3.14-6J ) "), 3.14-6j)
 
         class complex2(complex):
             pass
@@ -358,7 +358,7 @@
         b2 = '\N{MATHEMATICAL BOLD DIGIT TWO}' # &#120784;
         s = '{0} + {1}j'.format(b1, b2)
         assert complex(s) == 1+2j
-        assert complex('\N{EM SPACE}(1+1j)')
+        assert complex('\N{EM SPACE}(\N{EN SPACE}1+1j ) ') == 1+1j
 
     def test_hash(self):
         for x in range(-30, 30):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to