diff --git a/python/builtins.py b/python/builtins.py index 84ccd66b..3d37471f 100644 --- a/python/builtins.py +++ b/python/builtins.py @@ -259,4 +259,13 @@ def help(obj): class Exception: pass + +class classmethod: + def __init__(self, f): + self.f = f + raise NotImplementedError + +def staticmethod(f): + return f + from _long import long \ No newline at end of file diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index f03d0687..131305aa 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -192,10 +192,6 @@ void init_builtins(VM* _vm) { return VAR(PK_BITS(obj)); }); - _vm->bind_builtin_func<1>("staticmethod", [](VM* vm, ArgsView args) { - return args[0]; - }); - _vm->bind_builtin_func<1>("callable", [](VM* vm, ArgsView args) { PyObject* cls = vm->_t(args[0]); Type t = PK_OBJ_GET(Type, cls); diff --git a/tests/99_builtin_func.py b/tests/99_builtin_func.py index 2e445111..e79447b9 100644 --- a/tests/99_builtin_func.py +++ b/tests/99_builtin_func.py @@ -118,20 +118,20 @@ except: pass -# ----------------------------------------------- -# 114: 188: _vm->bind_builtin_func<1>("staticmethod", [](VM* vm, ArgsView args) { -# #####: 189: return args[0]; -# -: 190: }); -# test staticmethod: class A(): def __init__(self): self.a = 1 - @ staticmethod + @staticmethod def static_method(txt): return txt + + # @classmethod + # def class_method(cls, txt): + # return cls.__name__ + txt assert A.static_method(123) == 123 +# assert A.class_method(123) == 'A123' # 无法测试 ----------------------------------------------- # 248: 192: _vm->bind_builtin_func<1>("__import__", [](VM* vm, ArgsView args) {