mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
some change about mappingproxy
This commit is contained in:
parent
d53cd8e956
commit
9179c31d6a
@ -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"
|
||||||
|
@ -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;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user