blueloveTH 2 éve
szülő
commit
49f70318d9
3 módosított fájl, 15 hozzáadás és 10 törlés
  1. 9 0
      python/builtins.py
  2. 0 4
      src/pocketpy.cpp
  3. 6 6
      tests/99_builtin_func.py

+ 9 - 0
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

+ 0 - 4
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);

+ 6 - 6
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) {