Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 4595:f8f3da3fdaed legacy-trunk
Support __complex__ method on instances, for complex() conversion.
Keep gcc -Wall happy.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 05 Dec 1996 23:18:18 +0000 |
| parents | 65d2d8e67da3 |
| children | c75a2f2dc220 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Thu Dec 05 23:17:11 1996 +0000 +++ b/Python/bltinmodule.c Thu Dec 05 23:18:18 1996 +0000 @@ -308,6 +308,28 @@ "complex() argument can't be converted to complex"); return NULL; } + /* XXX Hack to support classes with __complex__ method */ + if (is_instanceobject(r)) { + static object *complexstr; + object *f; + if (complexstr == NULL) { + complexstr = newstringobject("__complex__"); + if (complexstr == NULL) + return NULL; + } + f = getattro(r, complexstr); + if (f == NULL) + err_clear(); + else { + object *args = mkvalue("()"); + if (args == NULL) + return NULL; + r = call_object(f, args); + DECREF(args); + if (r == NULL) + return NULL; + } + } if (is_complexobject(r)) cr = ((complexobject*)r)->cval; else { @@ -632,7 +654,7 @@ /* XXX Special case map(None, single_list) could be more efficient */ for (i = 0; ; ++i) { - object *alist, *item, *value; + object *alist, *item=NULL, *value; int any = 0; if (func == None && n == 1)
