[pypy-svn] pypy fast-forward: (lac, arigo)
arigo
commits-noreply at bitbucket.org
Sun Jan 16 16:50:36 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: fast-forward
Changeset: r40723:f1c048beb436
Date: 2011-01-16 16:39 +0100
http://bitbucket.org/pypy/pypy/changeset/f1c048beb436/
Log: (lac, arigo)
Fix the __complex__() method call: it must return really a complex
number object (and not e.g. a float). This is following CPython
(see test_cmath.py).
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
@@ -215,6 +215,8 @@
h.assertEqual(complex(NS(1+10j)), 1+10j)
h.raises(TypeError, complex, OS(None))
h.raises(TypeError, complex, NS(None))
+ h.raises(TypeError, complex, OS(2.0)) # __complex__ must really
+ h.raises(TypeError, complex, NS(2.0)) # return a complex, not a float
h.assertAlmostEqual(complex("1+10j"), 1+10j)
h.assertAlmostEqual(complex(10), 10+0j)
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
@@ -150,13 +150,11 @@
raise
else:
w_real = space.call_function(w_method)
- # __complex__() could return a string, which space.float()
- # could accept below... Let's catch this case.
- if (space.is_true(space.isinstance(w_imag, space.w_str)) or
- space.is_true(space.isinstance(w_imag, space.w_unicode))):
+ # __complex__() must return a complex object
+ if not space.is_true(space.isinstance(w_real, space.w_complex)):
raise OperationError(space.w_TypeError,
- space.wrap("__complex__() cannot return"
- " a string"))
+ space.wrap("__complex__() must return"
+ " a complex number"))
# at this point w_real can be an instance of 'complex',
# either because it is the result of __complex__() or because
More information about the Pypy-commit
mailing list