summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-01-04 00:43:01 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-01-04 00:43:01 (GMT)
commitecdae19fbe9506fffe6616d86f3bbf4a1858f3e2 (patch)
treec4ce3ae37922e1b9cfff5f835e2c2b55ad306ce1 /Objects
parent37559a085b423e4f2c1d512fb8296cae27c9317b (diff)
downloadcpython-ecdae19fbe9506fffe6616d86f3bbf4a1858f3e2.zip
cpython-ecdae19fbe9506fffe6616d86f3bbf4a1858f3e2.tar.gz
cpython-ecdae19fbe9506fffe6616d86f3bbf4a1858f3e2.tar.bz2
do correct lookup of the __complex__ method
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 298e262..60f2c15 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -1114,21 +1114,27 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
- /* XXX Hack to support classes with __complex__ method */
if (complexstr == NULL) {
complexstr = PyString_InternFromString("__complex__");
if (complexstr == NULL)
return NULL;
}
- f = PyObject_GetAttr(r, complexstr);
- if (f == NULL)
- PyErr_Clear();
+ if (PyInstance_Check(r)) {
+ f = PyObject_GetAttr(r, complexstr);
+ if (f == NULL) {
+ if (PyErr_ExceptionMatches(PyExc_AttributeError))
+ PyErr_Clear();
+ else
+ return NULL;
+ }
+ }
else {
- PyObject *args = PyTuple_New(0);
- if (args == NULL)
+ f = _PyObject_LookupSpecial(r, "__complex__", &complexstr);
+ if (f == NULL && PyErr_Occurred())
return NULL;
- r = PyEval_CallObject(f, args);
- Py_DECREF(args);
+ }
+ if (f != NULL) {
+ r = PyObject_CallFunctionObjArgs(f, NULL);
Py_DECREF(f);
if (r == NULL)
return NULL;