(original) (raw)

changeset: 104051:92f4ce2d5ebb branch: 3.5 parent: 104040:97ff9934ad2d user: Mark Dickinson dickinsm@gmail.com date: Sat Sep 24 15:26:36 2016 +0100 files: Lib/test/test_complex.py Misc/ACKS Misc/NEWS Objects/complexobject.c description: Issue #28203: Fix incorrect type in error message from complex(1.0, {2:3}). Patch by Soumya Sharma. diff -r 97ff9934ad2d -r 92f4ce2d5ebb Lib/test/test_complex.py --- a/Lib/test/test_complex.py Fri Sep 23 23:45:56 2016 +0000 +++ b/Lib/test/test_complex.py Sat Sep 24 15:26:36 2016 +0100 @@ -326,6 +326,14 @@ self.assertRaises(ValueError, complex, "1e1ej") self.assertRaises(ValueError, complex, "1e++1ej") self.assertRaises(ValueError, complex, ")1+2j(") + self.assertRaisesRegex( + TypeError, + "first argument must be a string or a number, not 'dict'", + complex, {1:2}, 1) + self.assertRaisesRegex( + TypeError, + "second argument must be a number, not 'dict'", + complex, 1, {1:2}) # the following three are accepted by Python 2.6 self.assertRaises(ValueError, complex, "1..1j") self.assertRaises(ValueError, complex, "1.11.1j") diff -r 97ff9934ad2d -r 92f4ce2d5ebb Misc/ACKS --- a/Misc/ACKS Fri Sep 23 23:45:56 2016 +0000 +++ b/Misc/ACKS Sat Sep 24 15:26:36 2016 +0100 @@ -1349,6 +1349,7 @@ Mark Shannon Ha Shao Richard Shapiro +Soumya Sharma Varun Sharma Daniel Shaulov Vlad Shcherbina diff -r 97ff9934ad2d -r 92f4ce2d5ebb Misc/NEWS --- a/Misc/NEWS Fri Sep 23 23:45:56 2016 +0000 +++ b/Misc/NEWS Sat Sep 24 15:26:36 2016 +0100 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #28203: Fix incorrect type in error message from + ``complex(1.0, {2:3})``. Patch by Soumya Sharma. + - Issue #27955: Fallback on reading /dev/urandom device when the getrandom() syscall fails with EPERM, for example when blocked by SECCOMP. diff -r 97ff9934ad2d -r 92f4ce2d5ebb Objects/complexobject.c --- a/Objects/complexobject.c Fri Sep 23 23:45:56 2016 +0000 +++ b/Objects/complexobject.c Sat Sep 24 15:26:36 2016 +0100 @@ -954,18 +954,29 @@ } nbr = r->ob_type->tp_as_number; - if (i != NULL) - nbi = i->ob_type->tp_as_number; - if (nbr == NULL || nbr->nb_float == NULL || - ((i != NULL) && (nbi == NULL || nbi->nb_float == NULL))) { + if (nbr == NULL || nbr->nb_float == NULL) { PyErr_Format(PyExc_TypeError, - "complex() argument must be a string or a number, not '%.200s'", - Py_TYPE(r)->tp_name); + "complex() first argument must be a string or a number, " + "not '%.200s'", + Py_TYPE(r)->tp_name); if (own_r) { Py_DECREF(r); } return NULL; } + if (i != NULL) { + nbi = i->ob_type->tp_as_number; + if (nbi == NULL || nbi->nb_float == NULL) { + PyErr_Format(PyExc_TypeError, + "complex() second argument must be a number, " + "not '%.200s'", + Py_TYPE(i)->tp_name); + if (own_r) { + Py_DECREF(r); + } + return NULL; + } + } /* If we get this far, then the "real" and "imag" parts should both be treated as numbers, and the constructor should return a /dickinsm@gmail.com