Modify String Constructor

This commit is contained in:
faze-geek 2024-03-12 17:43:20 +05:30
parent b0f6b54600
commit 2c95dd47d5
2 changed files with 5 additions and 1 deletions

View File

@ -496,7 +496,10 @@ void init_builtins(VM* _vm) {
});
// tp_str
_vm->bind_constructor<2>(_vm->_t(VM::tp_str), PK_LAMBDA(vm->py_str(args[1])));
_vm->bind_constructor<-1>(_vm->_t(VM::tp_str), [](VM* vm, ArgsView args) {
if(args.size() == 1) return VAR(Str());
return vm->py_str(args[1]);
});
_vm->bind__hash__(VM::tp_str, [](VM* vm, PyObject* _0) {
return (i64)_CAST(Str&, _0).hash();

View File

@ -14,6 +14,7 @@ assert repr('\\\n\t\'\r\b\x48') == r"'\\\n\t\'\r\bH'"
a = ''
b = 'test'
c ='test'
assert a == str()
assert len(a) == 0
assert len(b) == 4
assert b == c