mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
733c8935f9
commit
526c7a0101
3 changed files with 26 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue