mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Support __complex__ method on instances, for complex() conversion.
Keep gcc -Wall happy.
This commit is contained in:
parent
150b2df682
commit
ed0af8fe70
1 changed files with 23 additions and 1 deletions
|
@ -308,6 +308,28 @@ builtin_complex(self, args)
|
||||||
"complex() argument can't be converted to complex");
|
"complex() argument can't be converted to complex");
|
||||||
return NULL;
|
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))
|
if (is_complexobject(r))
|
||||||
cr = ((complexobject*)r)->cval;
|
cr = ((complexobject*)r)->cval;
|
||||||
else {
|
else {
|
||||||
|
@ -632,7 +654,7 @@ builtin_map(self, args)
|
||||||
|
|
||||||
/* XXX Special case map(None, single_list) could be more efficient */
|
/* XXX Special case map(None, single_list) could be more efficient */
|
||||||
for (i = 0; ; ++i) {
|
for (i = 0; ; ++i) {
|
||||||
object *alist, *item, *value;
|
object *alist, *item=NULL, *value;
|
||||||
int any = 0;
|
int any = 0;
|
||||||
|
|
||||||
if (func == None && n == 1)
|
if (func == None && n == 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue