mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
fix a bug of bool()
This commit is contained in:
parent
0979ba2a0a
commit
f4fe849432
@ -6710,6 +6710,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/************ PyBool ************/
|
/************ PyBool ************/
|
||||||
|
_vm->bindMethod("bool", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
|
vm->__checkArgSize(args, 1);
|
||||||
|
return vm->asBool(args[0]);
|
||||||
|
});
|
||||||
|
|
||||||
_vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
bool val = vm->PyBool_AS_C(args[0]);
|
bool val = vm->PyBool_AS_C(args[0]);
|
||||||
return vm->PyStr(val ? "True" : "False");
|
return vm->PyStr(val ? "True" : "False");
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit cb98c82ac6dc5cf83cb107d1cbf3fc9219e296e4
|
Subproject commit f0c35d535dca99b31b15100f82f48bc1becbca45
|
@ -6710,6 +6710,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/************ PyBool ************/
|
/************ PyBool ************/
|
||||||
|
_vm->bindMethod("bool", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
|
vm->__checkArgSize(args, 1);
|
||||||
|
return vm->asBool(args[0]);
|
||||||
|
});
|
||||||
|
|
||||||
_vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
bool val = vm->PyBool_AS_C(args[0]);
|
bool val = vm->PyBool_AS_C(args[0]);
|
||||||
return vm->PyStr(val ? "True" : "False");
|
return vm->PyStr(val ? "True" : "False");
|
||||||
|
@ -534,6 +534,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/************ PyBool ************/
|
/************ PyBool ************/
|
||||||
|
_vm->bindMethod("bool", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
|
vm->__checkArgSize(args, 1);
|
||||||
|
return vm->asBool(args[0]);
|
||||||
|
});
|
||||||
|
|
||||||
_vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
bool val = vm->PyBool_AS_C(args[0]);
|
bool val = vm->PyBool_AS_C(args[0]);
|
||||||
return vm->PyStr(val ? "True" : "False");
|
return vm->PyStr(val ? "True" : "False");
|
||||||
|
@ -75,6 +75,13 @@ assert True or False
|
|||||||
assert not False
|
assert not False
|
||||||
assert not (not True)
|
assert not (not True)
|
||||||
|
|
||||||
|
assert bool(0) == False
|
||||||
|
assert bool(1) == True
|
||||||
|
assert bool([]) == False
|
||||||
|
assert bool("abc") == True
|
||||||
|
assert bool([1,2]) == True
|
||||||
|
assert bool('') == False
|
||||||
|
|
||||||
# generate assert test for str
|
# generate assert test for str
|
||||||
|
|
||||||
assert 'testing' == 'test' + 'ing'
|
assert 'testing' == 'test' + 'ing'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user