fix a bug of bool()

This commit is contained in:
blueloveTH 2022-12-09 20:01:13 +08:00
parent 0979ba2a0a
commit f4fe849432
5 changed files with 23 additions and 1 deletions

View File

@ -6710,6 +6710,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
});
/************ 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) {
bool val = vm->PyBool_AS_C(args[0]);
return vm->PyStr(val ? "True" : "False");

@ -1 +1 @@
Subproject commit cb98c82ac6dc5cf83cb107d1cbf3fc9219e296e4
Subproject commit f0c35d535dca99b31b15100f82f48bc1becbca45

View File

@ -6710,6 +6710,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
});
/************ 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) {
bool val = vm->PyBool_AS_C(args[0]);
return vm->PyStr(val ? "True" : "False");

View File

@ -534,6 +534,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
});
/************ 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) {
bool val = vm->PyBool_AS_C(args[0]);
return vm->PyStr(val ? "True" : "False");

View File

@ -75,6 +75,13 @@ assert True or False
assert not False
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
assert 'testing' == 'test' + 'ing'