blueloveTH 3 лет назад
Родитель
Сommit
3ddeac241a
2 измененных файлов с 12 добавлено и 3 удалено
  1. 9 2
      src/pocketpy.h
  2. 3 1
      tests/pointer.py

+ 9 - 2
src/pocketpy.h

@@ -556,15 +556,22 @@ void __initializeBuiltinFunctions(VM* _vm) {
     });
 
     _vm->bindMethod("_native_function", "__call__", [](VM* vm, const pkpy::ArgList& args) {
-        vm->__checkType(args[0], vm->_tp_native_function);
         const _CppFunc& _self = vm->PyNativeFunction_AS_C(args[0]);
         return _self(vm, args.subList(1));
     });
 
     _vm->bindMethod("function", "__call__", [](VM* vm, const pkpy::ArgList& args) {
-        vm->__checkType(args[0], vm->_tp_function);
         return vm->call(args[0], args.subList(1));
     });
+
+    _vm->bindMethod("_bounded_method", "__call__", [](VM* vm, const pkpy::ArgList& args) {
+        vm->__checkType(args[0], vm->_tp_bounded_method);
+        const _BoundedMethod& _self = vm->PyBoundedMethod_AS_C(args[0]);
+        pkpy::ArgList newArgs(args.size());
+        newArgs[0] = _self.obj;
+        for(int i = 1; i < args.size(); i++) newArgs[i] = args[i];
+        return vm->call(_self.method, newArgs);
+    });
 }
 
 #include "builtins.h"

+ 3 - 1
tests/pointer.py

@@ -28,7 +28,9 @@ def add(a, b):
 
 p = &add
 assert p->__call__(1, 2) == 3
+assert p->__call__.__call__.__call__.__call__.__call__(3, 4) == 7
 
 fun = lambda :6
 p = &fun
-assert p->__call__() == 6
+assert p->__call__() == 6
+assert p->__call__.__call__.__call__.__call__.__call__() == 6