Ensure that complex() only accepts a string argument as the first arg,

and only if there is no second arg.
This closes SF patch #479551.
This commit is contained in:
Fred Drake 2001-12-13 19:52:22 +00:00
parent 733c8935f9
commit 526c7a0101
3 changed files with 26 additions and 4 deletions

View file

@ -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)