aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2016-09-24 15:26:36 +0100
committerMark Dickinson <dickinsm@gmail.com>2016-09-24 15:26:36 +0100
commit613f8e513cf171a335318221b6050d470a1d765f (patch)
tree3fe6661b6a39246e34d85745b8bbd836cbcb7623 /Objects/complexobject.c
parentIssue #28221: Remove unused assignment from test_asyncore_server() (diff)
downloadcpython-613f8e513cf171a335318221b6050d470a1d765f.tar.gz
cpython-613f8e513cf171a335318221b6050d470a1d765f.tar.bz2
cpython-613f8e513cf171a335318221b6050d470a1d765f.zip
Issue #28203: Fix incorrect type in error message from complex(1.0, {2:3}). Patch by Soumya Sharma.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index a5bfb667c46..d82c5eb9f1e 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -954,18 +954,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