Mercurial > cpython-lru_cache-weakref
diff Objects/complexobject.c @ 21399:33d59e18b68d legacy-trunk
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.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Thu, 13 Dec 2001 19:52:22 +0000 |
| parents | 025ad27d4224 |
| children | f245955b3fbe |
line wrap: on
line diff
--- a/Objects/complexobject.c Thu Dec 13 19:51:56 2001 +0000 +++ b/Objects/complexobject.c Thu Dec 13 19:52:22 2001 +0000 @@ -806,8 +806,20 @@ 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)
