summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-09-29 09:45:57 (GMT)
committerGuido van Rossum <guido@python.org>1994-09-29 09:45:57 (GMT)
commit180d7b4d5588737601b3242d8ce9cab59a75286f (patch)
treeb5ac47852aa67c7bf2b1a82eaf0b0117b314e348 /Python/bltinmodule.c
parentfe3f1a256bc4f0c359ab843d5de517946916218f (diff)
downloadcpython-180d7b4d5588737601b3242d8ce9cab59a75286f.zip
cpython-180d7b4d5588737601b3242d8ce9cab59a75286f.tar.gz
cpython-180d7b4d5588737601b3242d8ce9cab59a75286f.tar.bz2
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
global: Py_MakePendingCalls. Also guard against recursive calls * Include/classobject.h, Objects/classobject.c, Python/{ceval.c,bltinmodule.c}: entirely redone operator overloading. The rules for class instances are now much more relaxed than for other built-in types (whose coerce must still return two objects of the same type)
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index b38ed5b..3acf187 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -243,6 +243,8 @@ builtin_coerce(self, args)
if (!getargs(args, "(OO)", &v, &w))
return NULL;
+ if (is_instanceobject(v) || is_instanceobject(w))
+ return instancebinop(v, w, "__coerce__", "__rcoerce__");
if (coerce(&v, &w) < 0)
return NULL;
res = mkvalue("(OO)", v, w);
@@ -314,9 +316,11 @@ builtin_divmod(self, args)
object *v, *w, *x;
if (!getargs(args, "(OO)", &v, &w))
return NULL;
+ if (is_instanceobject(v) || is_instanceobject(w))
+ return instancebinop(v, w, "__divmod__", "__rdivmod__");
if (v->ob_type->tp_as_number == NULL ||
w->ob_type->tp_as_number == NULL) {
- err_setstr(TypeError, "divmod() requires numeric arguments");
+ err_setstr(TypeError, "divmod() requires numeric or class instance arguments");
return NULL;
}
if (coerce(&v, &w) != 0)
@@ -876,11 +880,16 @@ builtin_pow(self, args)
{
object *v, *w, *z, *x;
z = None;
- if (!getargs(args, "(OO)", &v, &w)) {
- err_clear();
- if (!getargs(args, "(OOO)", &v, &w, &z)) {
- return NULL;
- }
+ if (!newgetargs(args, "OO|O", &v, &w, &z))
+ return NULL;
+ if (z == None) {
+ if (is_instanceobject(v) || is_instanceobject(w))
+ return instancebinop(v, w, "__pow__", "__rpow__");
+ }
+ else {
+ /* XXX The ternary version doesn't do coercions */
+ if (is_instanceobject(v))
+ return v->ob_type->tp_as_number->nb_power(v, w, z);
}
if (v->ob_type->tp_as_number == NULL ||
(z!=None && z->ob_type->tp_as_number == NULL) ||