Skip to content

Commit 6997946

Browse files
committed
Issue #28203: Merge from 3.5
2 parents 938da64 + 613f8e5 commit 6997946

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

Lib/test/test_complex.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ def split_zeros(x):
328328
self.assertRaises(ValueError, complex, "1e1ej")
329329
self.assertRaises(ValueError, complex, "1e++1ej")
330330
self.assertRaises(ValueError, complex, ")1+2j(")
331+
self.assertRaisesRegex(
332+
TypeError,
333+
"first argument must be a string or a number, not 'dict'",
334+
complex, {1:2}, 1)
335+
self.assertRaisesRegex(
336+
TypeError,
337+
"second argument must be a number, not 'dict'",
338+
complex, 1, {1:2})
331339
# the following three are accepted by Python 2.6
332340
self.assertRaises(ValueError, complex, "1..1j")
333341
self.assertRaises(ValueError, complex, "1.11.1j")

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ Daniel Shahaf
13691369
Mark Shannon
13701370
Ha Shao
13711371
Richard Shapiro
1372+
Soumya Sharma
13721373
Varun Sharma
13731374
Daniel Shaulov
13741375
Vlad Shcherbina

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #28203: Fix incorrect type in complex(1.0, {2:3}) error message.
14+
Patch by Soumya Sharma.
15+
1316
- Issue #28086: Single var-positional argument of tuple subtype was passed
1417
unscathed to the C-defined function. Now it is converted to exact tuple.
1518

Objects/complexobject.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -965,18 +965,29 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
965965
}
966966

967967
nbr = r->ob_type->tp_as_number;
968-
if (i != NULL)
969-
nbi = i->ob_type->tp_as_number;
970-
if (nbr == NULL || nbr->nb_float == NULL ||
971-
((i != NULL) && (nbi == NULL || nbi->nb_float == NULL))) {
968+
if (nbr == NULL || nbr->nb_float == NULL) {
972969
PyErr_Format(PyExc_TypeError,
973-
"complex() argument must be a string or a number, not '%.200s'",
974-
Py_TYPE(r)->tp_name);
970+
"complex() first argument must be a string or a number, "
971+
"not '%.200s'",
972+
Py_TYPE(r)->tp_name);
975973
if (own_r) {
976974
Py_DECREF(r);
977975
}
978976
return NULL;
979977
}
978+
if (i != NULL) {
979+
nbi = i->ob_type->tp_as_number;
980+
if (nbi == NULL || nbi->nb_float == NULL) {
981+
PyErr_Format(PyExc_TypeError,
982+
"complex() second argument must be a number, "
983+
"not '%.200s'",
984+
Py_TYPE(i)->tp_name);
985+
if (own_r) {
986+
Py_DECREF(r);
987+
}
988+
return NULL;
989+
}
990+
}
980991

981992
/* If we get this far, then the "real" and "imag" parts should
982993
both be treated as numbers, and the constructor should return a

0 commit comments

Comments
 (0)