diff options
author | Brett Cannon <brett@python.org> | 2012-11-14 20:22:56 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-11-14 20:22:56 (GMT) |
commit | 6f7e81a549674802ee13a2a217974d57751ac111 (patch) | |
tree | da3bad502fd82be344b87f11be469044cd771fd0 | |
parent | cd8efa3704bc1aec1338fdc8fc0cfe8ee5bc100e (diff) | |
parent | d20fb8219554989f3ed901c144014d2f4c5a300a (diff) | |
download | cpython-6f7e81a549674802ee13a2a217974d57751ac111.zip cpython-6f7e81a549674802ee13a2a217974d57751ac111.tar.gz cpython-6f7e81a549674802ee13a2a217974d57751ac111.tar.bz2 |
merge
-rw-r--r-- | Lib/test/test_complex.py | 2 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/complexobject.c | 12 |
3 files changed, 11 insertions, 6 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 6b34ddc..2a85bf4 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -221,6 +221,8 @@ class ComplexTest(unittest.TestCase): self.assertRaises(TypeError, complex, OS(None)) self.assertRaises(TypeError, complex, NS(None)) self.assertRaises(TypeError, complex, {}) + self.assertRaises(TypeError, complex, NS(1.5)) + self.assertRaises(TypeError, complex, NS(1)) self.assertAlmostEqual(complex("1+10j"), 1+10j) self.assertAlmostEqual(complex(10), 10+0j) @@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #16290: A float return value from the __complex__ special method is no + longer accepted in the complex() constructor. + - Issue #16416: On Mac OS X, operating system data are now always encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no locale environment variable is set), to avoid diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 403c60c..355b063 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -271,6 +271,12 @@ try_complex_special_method(PyObject *op) { if (f) { PyObject *res = PyObject_CallFunctionObjArgs(f, NULL); Py_DECREF(f); + if (res != NULL && !PyComplex_Check(res)) { + PyErr_SetString(PyExc_TypeError, + "__complex__ should return a complex object"); + Py_DECREF(res); + return NULL; + } return res; } return NULL; @@ -296,12 +302,6 @@ PyComplex_AsCComplex(PyObject *op) newop = try_complex_special_method(op); if (newop) { - if (!PyComplex_Check(newop)) { - PyErr_SetString(PyExc_TypeError, - "__complex__ should return a complex object"); - Py_DECREF(newop); - return cv; - } cv = ((PyComplexObject *)newop)->cval; Py_DECREF(newop); return cv; |