summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-08-29 14:22:51 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-08-29 14:22:51 (GMT)
commit604cd6ae79e0e7ff52b96bba9aa9fbd6c21e1e8f (patch)
tree27b2038b8e2cf8bec7908a467a3e1e68655f243a /Objects
parent18bd11205d5a477e9be9cd70a3cbcc7eeae6fc9b (diff)
downloadcpython-604cd6ae79e0e7ff52b96bba9aa9fbd6c21e1e8f.zip
cpython-604cd6ae79e0e7ff52b96bba9aa9fbd6c21e1e8f.tar.gz
cpython-604cd6ae79e0e7ff52b96bba9aa9fbd6c21e1e8f.tar.bz2
complex() was the only numeric constructor that created a new instance
when given its own type as an argument.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index bb28354..56638d5 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -823,6 +823,15 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:complex", kwlist,
&r, &i))
return NULL;
+
+ /* Special-case for single argumet that is already complex */
+ if (PyComplex_CheckExact(r) && i == NULL) {
+ /* Note that we can't know whether it's safe to return
+ a complex *subclass* instance as-is, hence the restriction
+ to exact complexes here. */
+ Py_INCREF(r);
+ return r;
+ }
if (PyString_Check(r) || PyUnicode_Check(r)) {
if (i != NULL) {
PyErr_SetString(PyExc_TypeError,