[pypy-svn] pypy default: Fix parsing for complex("+J")
alex_gaynor
commits-noreply at bitbucket.org
Mon Jan 24 22:57:29 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41270:1f581d23d761
Date: 2011-01-24 16:56 -0500
http://bitbucket.org/pypy/pypy/changeset/1f581d23d761/
Log: Fix parsing for complex("+J")
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
@@ -40,6 +40,8 @@
test_cparse('(1+2j)', '1', '2')
test_cparse('(1-6j)', '1', '-6')
test_cparse(' ( +3.14-6J )','+3.14','-6')
+ test_cparse(' +J','0.0','1.0')
+ test_cparse(' -J','0.0','-1.0')
def test_unpackcomplex(self):
space = self.space
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
@@ -60,6 +60,10 @@
if s[newstop] in ('j','J'):
if realstart == newstop:
imagpart = '1.0'
+ elif realstart == newstop-1 and s[realstart] == '+':
+ imagpart = '1.0'
+ elif realstart == newstop-1 and s[realstart] == '-':
+ imagpart = '-1.0'
else:
imagpart = s[realstart:newstop]
return '0.0', imagpart
More information about the Pypy-commit
mailing list