summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 18dfa7d..1ee1c54 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -806,8 +806,20 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:complex", kwlist,
&r, &i))
return NULL;
- if (PyString_Check(r) || PyUnicode_Check(r))
+ if (PyString_Check(r) || PyUnicode_Check(r)) {
+ if (i != NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "complex() can't take second arg"
+ " if first is a string");
+ return NULL;
+ }
return complex_subtype_from_string(type, r);
+ }
+ if (i != NULL && (PyString_Check(i) || PyUnicode_Check(i))) {
+ PyErr_SetString(PyExc_TypeError,
+ "complex() second arg can't be a string");
+ return NULL;
+ }
nbr = r->ob_type->tp_as_number;
if (i != NULL)