diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-30 17:15:20 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-30 17:15:20 (GMT) |
commit | 6b4ec5135b72eddcb7ed062bb5b466a92795f911 (patch) | |
tree | 187dccda3de56b1e2f592f40194eb9142dfafe5e /Python/ceval.c | |
parent | 5942b439b366b83880a2678793d36b931acef75b (diff) | |
download | cpython-6b4ec5135b72eddcb7ed062bb5b466a92795f911.zip cpython-6b4ec5135b72eddcb7ed062bb5b466a92795f911.tar.gz cpython-6b4ec5135b72eddcb7ed062bb5b466a92795f911.tar.bz2 |
Fix for SF bug #117241
When a method is called with no regular arguments and * args, defer
the first arg is subclass check until after the * args have been
expanded.
N.B. The CALL_FUNCTION implementation is getting really hairy; should
review it to see if it can be simplified.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index df057b7..ad6e792 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1822,7 +1822,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, na++; n++; } - else { + else if (!((flags & 1) && na == 0)) { /* Unbound methods must be called with an instance of the class (or a derived class) as first argument */ @@ -1895,6 +1895,20 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, if (nstar < 0) { goto extcall_fail; } + if (class && self == NULL && na == 0) { + /* * arg is first argument of method, + so check it is isinstance of class */ + self = PyTuple_GET_ITEM(stararg, 0); + if (!(PyInstance_Check(self) && + PyClass_IsSubclass((PyObject *) + (((PyInstanceObject *)self)->in_class), + class))) { + PyErr_SetString(PyExc_TypeError, + "unbound method must be called with instance as first argument"); + x = NULL; + break; + } + } } if (nk > 0) { if (kwdict == NULL) { |