mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-13 13:40:16 +00:00
fix error of "A() takes no arguments"
This commit is contained in:
parent
5c7fb79a14
commit
6cad72453b
@ -580,6 +580,7 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall
|
||||
// [cls, NULL, args..., kwargs...]
|
||||
py_Ref new_f = py_tpfindmagic(py_totype(p0), __new__);
|
||||
assert(new_f && py_isnil(p0 + 1));
|
||||
bool is_default_new = new_f->type == tp_nativefunc && new_f->_cfunc == pk__object_new;
|
||||
|
||||
// prepare a copy of args and kwargs
|
||||
int span = self->stack.sp - argv;
|
||||
@ -603,6 +604,13 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall
|
||||
// [__init__, self, args..., kwargs...]
|
||||
if(VM__vectorcall(self, argc, kwargc, false) == RES_ERROR) return RES_ERROR;
|
||||
*py_retval() = p0[1]; // restore the new instance
|
||||
} else {
|
||||
if(is_default_new) {
|
||||
if(argc != 0 || kwargc != 0) {
|
||||
TypeError("%t() takes no arguments", p0->type);
|
||||
return RES_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
// reset the stack
|
||||
self->stack.sp = p0;
|
||||
|
||||
@ -135,4 +135,24 @@ assert MyClass.b == 1
|
||||
assert MyClass.c == 2
|
||||
assert MyClass.d == 3
|
||||
|
||||
assert MyClass(1, 2).m == 1
|
||||
assert MyClass(1, 2).m == 1
|
||||
|
||||
class E: pass
|
||||
try:
|
||||
E(1,2,3)
|
||||
exit(1)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
class E1:
|
||||
def __new__(cls, a, b):
|
||||
o = object.__new__(cls)
|
||||
o.a = a
|
||||
o.b = b
|
||||
return o
|
||||
|
||||
def sum(self):
|
||||
return self.a + self.b
|
||||
|
||||
e1 = E1(3,4)
|
||||
assert e1.sum() == 7
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user