Kaynağa Gözat

fix int() builtins for u32 type

Lyon 2 yıl önce
ebeveyn
işleme
f96fdbc0f1

+ 2 - 0
examples/builtins/bool.py

@@ -83,4 +83,6 @@ assert compare_strings('abc', 'abc') == True
 assert compare_strings('abc', 'def') == False
 assert is_string_not_empty('abc') == True
 
+assert int(0xFFFFFFFF) == 0xFFFFFFFF
+
 print("PASS")

+ 1 - 1
package/PikaStdLib/builtins.pyi

@@ -1,7 +1,7 @@
 from PikaObj import *
 
 
-def int(arg: any, *base) -> int: ...
+def int(arg: any, *base) -> any: ...
 
 
 def bool(arg: any) -> bool: ...

+ 1 - 1
port/linux/package/pikascript/builtins.pyi

@@ -1,7 +1,7 @@
 from PikaObj import *
 
 
-def int(arg: any, *base) -> int: ...
+def int(arg: any, *base) -> any: ...
 
 
 def bool(arg: any) -> bool: ...

+ 2 - 0
port/linux/test/python/builtins/bool.py

@@ -83,4 +83,6 @@ assert compare_strings('abc', 'abc') == True
 assert compare_strings('abc', 'def') == False
 assert is_string_not_empty('abc') == True
 
+assert int(0xFFFFFFFF) == 0xFFFFFFFF
+
 print("PASS")

+ 4 - 4
src/PikaObj.c

@@ -3030,7 +3030,7 @@ PIKA_RES _transeBool(Arg* arg, pika_bool* res) {
     return PIKA_RES_ERR_INVALID_PARAM;
 }
 
-int builtins_int(PikaObj* self, Arg* arg, PikaTuple* base) {
+Arg* builtins_int(PikaObj* self, Arg* arg, PikaTuple* base) {
     int64_t res = 0;
     int64_t iBase = 10;
     if (pikaTuple_getSize(base) > 0) {
@@ -3040,16 +3040,16 @@ int builtins_int(PikaObj* self, Arg* arg, PikaTuple* base) {
                           "TypeError: int() can't convert non-string with "
                           "explicit base");
             obj_setErrorCode(self, 1);
-            return _PIKA_INT_ERR;
+            return NULL;
         }
         iBase = (int64_t)pikaTuple_getInt(base, 0);
     }
     if (_transeInt(arg, iBase, &res) == PIKA_RES_OK) {
-        return res;
+        return arg_newInt(res);
     }
     obj_setSysOut(self, "ValueError: invalid literal for int()");
     obj_setErrorCode(self, 1);
-    return _PIKA_INT_ERR;
+    return NULL;
 }
 
 pika_bool builtins_bool(PikaObj* self, Arg* arg) {