Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r58168:6d1ad31ec914
Date: 2012-10-17 14:38 +0200
http://bitbucket.org/pypy/pypy/changeset/6d1ad31ec914/
Log: manually revert f1c048beb436: this has never been true on CPython,
no clue why it was introduced
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
@@ -190,13 +190,18 @@
w_z = space.get_and_call_function(w_method, w_complex)
#
if w_z is not None:
- # __complex__() must return a complex object
+ # __complex__() must return a complex or (float,int,long) object
# (XXX should not use isinstance here)
- if not isinstance(w_z, W_ComplexObject):
- raise OperationError(space.w_TypeError,
- space.wrap("__complex__() must return"
- " a complex number"))
- return (w_z.realval, w_z.imagval)
+ if (space.isinstance_w(w_z, space.w_int) or
+ space.isinstance_w(w_z, space.w_long) or
+ space.isinstance_w(w_z, space.w_float)):
+ return (space.float_w(w_z), 0.0)
+ elif isinstance(w_z, W_ComplexObject):
+ return (w_z.realval, w_z.imagval)
+ raise OperationError(space.w_TypeError,
+ space.wrap("__complex__() must return"
+ " a number"))
+
#
# no '__complex__' method, so we assume it is a float,
# unless it is an instance of some subclass of complex.
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
@@ -249,10 +249,16 @@
assert complex(NS(1+10j), 5) == 1+15j
assert complex(OS(1+10j), 5j) == -4+10j
assert complex(NS(1+10j), 5j) == -4+10j
+
+ assert complex(OS(2.0)) == 2+0j
+ assert complex(NS(2.0)) == 2+0j
+ assert complex(OS(2)) == 2+0j
+ assert complex(NS(2)) == 2+0j
+ assert complex(OS(2L)) == 2+0j
+ assert complex(NS(2L)) == 2+0j
+
raises(TypeError, complex, OS(None))
raises(TypeError, complex, NS(None))
- raises(TypeError, complex, OS(2.0)) # __complex__ must really
- raises(TypeError, complex, NS(2.0)) # return a complex, not a float
# -- The following cases are not supported by CPython, but they
# -- are supported by PyPy, which is most probably ok
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit