summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-12-13 19:52:22 (GMT)
committerFred Drake <fdrake@acm.org>2001-12-13 19:52:22 (GMT)
commit526c7a0101d826fdab8b1ef5a757e1eae351687c (patch)
treefe3c026e4862df026da3aa91eba621e19f29877c /Objects/complexobject.c
parent733c8935f9dfd1be70c472649eb845ea22bbc878 (diff)
downloadcpython-526c7a0101d826fdab8b1ef5a757e1eae351687c.zip
cpython-526c7a0101d826fdab8b1ef5a757e1eae351687c.tar.gz
cpython-526c7a0101d826fdab8b1ef5a757e1eae351687c.tar.bz2
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.
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)