[pypy-commit] pypy default: more cleanups for complex parsing str

bdkearns noreply at buildbot.pypy.org
Thu May 8 23:37:01 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r71422:0cecb9c518a9
Date: 2014-05-08 17:36 -0400
http://bitbucket.org/pypy/pypy/changeset/0cecb9c518a9/

Log:	more cleanups for complex parsing str

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
@@ -38,12 +38,14 @@
         # ignore whitespace after bracket
         while i < slen and s[i] == ' ':
             i += 1
+        while slen > 0 and s[slen-1] == ' ':
+            slen -= 1
 
     # extract first number
     realstart = i
     pc = s[i]
     while i < slen and s[i] != ' ':
-        if s[i] in ('+','-') and pc not in ('e','E') and i != realstart:
+        if s[i] in ('+', '-') and pc not in ('e', 'E') and i != realstart:
             break
         pc = s[i]
         i += 1
@@ -71,10 +73,10 @@
     # find sign for imaginary part
     if s[i] == '-' or s[i] == '+':
         imagsign = s[i]
-    if imagsign == ' ':
+    else:
         raise ValueError
 
-    i+=1
+    i += 1
     # whitespace
     while i < slen and s[i] == ' ':
         i += 1
@@ -84,7 +86,7 @@
     imagstart = i
     pc = s[i]
     while i < slen and s[i] != ' ':
-        if s[i] in ('+','-') and pc not in ('e','E'):
+        if s[i] in ('+', '-') and pc not in ('e', 'E'):
             break
         pc = s[i]
         i += 1
@@ -92,14 +94,12 @@
     imagstop = i - 1
     if imagstop < 0:
         raise ValueError
-    if s[imagstop] not in ('j','J'):
+    if s[imagstop] not in ('j', 'J'):
         raise ValueError
     if imagstop < imagstart:
         raise ValueError
 
-    while i<slen and s[i] == ' ':
-        i += 1
-    if i <  slen:
+    if i < slen:
         raise ValueError
 
     realpart = s[realstart:realstop]
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
@@ -38,6 +38,7 @@
         test_cparse('(1+2j)', '1', '2')
         test_cparse('(1-6j)', '1', '-6')
         test_cparse(' ( +3.14-6J )', '+3.14', '-6')
+        test_cparse(' ( +3.14- 6J ) ', '+3.14', '-6')
         test_cparse(' +J', '0.0', '1.0')
         test_cparse(' -J', '0.0', '-1.0')
 


More information about the pypy-commit mailing list