# HG changeset patch # User soummyaah # Date 1474372848 -19800 # Tue Sep 20 17:30:48 2016 +0530 # Node ID 9cd9ad17738a006f2b3bbb1fe397092f5cb5a262 # Parent f73856b15eee05226aa9fff2b6c444600e27af5a Changed 'arguments' to 'arg' in error message diff -r f73856b15eee -r 9cd9ad17738a Lib/test/test_complex.py --- a/Lib/test/test_complex.py Tue Sep 20 17:25:19 2016 +0530 +++ b/Lib/test/test_complex.py Tue Sep 20 17:30:48 2016 +0530 @@ -328,8 +328,8 @@ 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}) + self.assertRaisesRegex(TypeError, "first arg must be a string or a number, not 'dict'", complex, {1:2}, 1) + self.assertRaisesRegex(TypeError, "second arg 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 f73856b15eee -r 9cd9ad17738a Objects/complexobject.c --- a/Objects/complexobject.c Tue Sep 20 17:25:19 2016 +0530 +++ b/Objects/complexobject.c Tue Sep 20 17:30:48 2016 +0530 @@ -969,7 +969,7 @@ nbi = i->ob_type->tp_as_number; if (nbr == NULL || nbr->nb_float == NULL) { PyErr_Format(PyExc_TypeError, - "complex() first argument must be a string or a number, not '%.200s'", + "complex() first arg must be a string or a number, not '%.200s'", Py_TYPE(r)->tp_name); if (own_r) { Py_DECREF(r); @@ -978,7 +978,7 @@ } if (i != NULL && (nbi == NULL || nbi->nb_float == NULL)) { PyErr_Format(PyExc_TypeError, - "complex() second argument must be a number, not '%.200s'", + "complex() second arg must be a number, not '%.200s'", Py_TYPE(i)->tp_name); if (own_r) { Py_DECREF(r); # HG changeset patch # User soummyaah # Date 1474372519 -19800 # Tue Sep 20 17:25:19 2016 +0530 # Node ID f73856b15eee05226aa9fff2b6c444600e27af5a # Parent b0a1d8435af89a8e8c375882c1d0b24d9c43a823 Modified tests to check for complete Error string diff -r b0a1d8435af8 -r f73856b15eee Lib/test/test_complex.py --- a/Lib/test/test_complex.py Tue Sep 20 09:44:27 2016 +0530 +++ b/Lib/test/test_complex.py Tue Sep 20 17:25:19 2016 +0530 @@ -328,8 +328,8 @@ self.assertRaises(ValueError, complex, "1e1ej") self.assertRaises(ValueError, complex, "1e++1ej") self.assertRaises(ValueError, complex, ")1+2j(") - self.assertRaisesRegex(TypeError, "first argument", complex, {1:2}, 1) - self.assertRaisesRegex(TypeError, "second argument", complex, 1, {1:2}) + 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") # HG changeset patch # User soummyaah # Date 1474344867 -19800 # Tue Sep 20 09:44:27 2016 +0530 # Node ID b0a1d8435af89a8e8c375882c1d0b24d9c43a823 # Parent 4cfb35dca5e89849af1e9c2f8c44cc64cc36e0f1 Issue #28203: Changed the error message returned when second argument of complex() is not number/string diff -r 4cfb35dca5e8 -r b0a1d8435af8 Lib/test/test_complex.py --- a/Lib/test/test_complex.py Mon Sep 19 11:56:06 2016 +0200 +++ b/Lib/test/test_complex.py Tue Sep 20 09:44:27 2016 +0530 @@ -328,6 +328,8 @@ self.assertRaises(ValueError, complex, "1e1ej") self.assertRaises(ValueError, complex, "1e++1ej") self.assertRaises(ValueError, complex, ")1+2j(") + self.assertRaisesRegex(TypeError, "first argument", complex, {1:2}, 1) + self.assertRaisesRegex(TypeError, "second argument", 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 4cfb35dca5e8 -r b0a1d8435af8 Objects/complexobject.c --- a/Objects/complexobject.c Mon Sep 19 11:56:06 2016 +0200 +++ b/Objects/complexobject.c Tue Sep 20 09:44:27 2016 +0530 @@ -967,16 +967,24 @@ 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'", + "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 == 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