summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2016-09-24 14:28:34 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2016-09-24 14:28:34 (GMT)
commit6997946ec45378b3e9aa7d2f8c500bbcb9821739 (patch)
tree1ef91b27c2f770d9aabd4c650afc75534120c40a
parent938da643ee4ad16a4cca65e0badd6d315feaed4f (diff)
parent613f8e513cf171a335318221b6050d470a1d765f (diff)
downloadcpython-6997946ec45378b3e9aa7d2f8c500bbcb9821739.zip
cpython-6997946ec45378b3e9aa7d2f8c500bbcb9821739.tar.gz
cpython-6997946ec45378b3e9aa7d2f8c500bbcb9821739.tar.bz2
Issue #28203: Merge from 3.5
-rw-r--r--Lib/test/test_complex.py8
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/complexobject.c23
4 files changed, 29 insertions, 6 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 6633a7a..c249ca7 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -328,6 +328,14 @@ class ComplexTest(unittest.TestCase):
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 --git a/Misc/ACKS b/Misc/ACKS
index 7ceee35..34d2fd3 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1369,6 +1369,7 @@ Daniel Shahaf
Mark Shannon
Ha Shao
Richard Shapiro
+Soumya Sharma
Varun Sharma
Daniel Shaulov
Vlad Shcherbina
diff --git a/Misc/NEWS b/Misc/NEWS
index db82215..e9b22be 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
Core and Builtins
-----------------
+- Issue #28203: Fix incorrect type in complex(1.0, {2:3}) error message.
+ Patch by Soumya Sharma.
+
- Issue #28086: Single var-positional argument of tuple subtype was passed
unscathed to the C-defined function. Now it is converted to exact tuple.
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index a9d5ec3..31e1278 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -965,18 +965,29 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
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