]> granicus.if.org Git - python/commitdiff
Support __complex__ method on instances, for complex() conversion.
authorGuido van Rossum <guido@python.org>
Thu, 5 Dec 1996 23:18:18 +0000 (23:18 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 5 Dec 1996 23:18:18 +0000 (23:18 +0000)
Keep gcc -Wall happy.

Python/bltinmodule.c

index 142a4f7189579b9976bd1ff6ebb348cc09b09cb7..6a81c911ca5602a99336658612edc1015e429c0c 100644 (file)
@@ -308,6 +308,28 @@ builtin_complex(self, args)
                           "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 @@ builtin_map(self, args)
 
        /* 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)