some change about mappingproxy

This commit is contained in:
blueloveTH 2023-12-02 16:22:08 +08:00
parent d53cd8e956
commit 9179c31d6a
2 changed files with 10 additions and 2 deletions

View File

@ -23,7 +23,7 @@
#include <bitset> #include <bitset>
#include <deque> #include <deque>
#define PK_VERSION "1.3.1" #define PK_VERSION "1.3.2"
#include "config.h" #include "config.h"
#include "export.h" #include "export.h"

View File

@ -1050,8 +1050,16 @@ void init_builtins(VM* _vm) {
_vm->bind__getitem__(_vm->tp_mappingproxy, [](VM* vm, PyObject* obj, PyObject* index) { _vm->bind__getitem__(_vm->tp_mappingproxy, [](VM* vm, PyObject* obj, PyObject* index) {
MappingProxy& self = _CAST(MappingProxy&, obj); MappingProxy& self = _CAST(MappingProxy&, obj);
StrName key = CAST(Str&, index); StrName key = CAST(Str&, index);
PyObject* ret = self.attr().try_get_likely_found(key);
if(ret == nullptr) vm->KeyError(index);
return ret;
});
_vm->bind(_vm->_t(_vm->tp_mappingproxy), "get(self, key, default=None)", [](VM* vm, ArgsView args) {
MappingProxy& self = _CAST(MappingProxy&, args[0]);
StrName key = CAST(Str&, args[1]);
PyObject* ret = self.attr().try_get(key); PyObject* ret = self.attr().try_get(key);
if(ret == nullptr) vm->AttributeError(key.sv()); if(ret == nullptr) return args[2];
return ret; return ret;
}); });