summaryrefslogtreecommitdiff
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2016-09-24 15:28:34 +0100
committerMark Dickinson <dickinsm@gmail.com>2016-09-24 15:28:34 +0100
commit6997946ec45378b3e9aa7d2f8c500bbcb9821739 (patch)
tree1ef91b27c2f770d9aabd4c650afc75534120c40a /Objects/complexobject.c
parent938da643ee4ad16a4cca65e0badd6d315feaed4f (diff)
parent613f8e513cf171a335318221b6050d470a1d765f (diff)
downloadcpython-git-6997946ec45378b3e9aa7d2f8c500bbcb9821739.tar.gz
Issue #28203: Merge from 3.5
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 a9d5ec301a..31e12784cc 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