mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
2305092c7d
commit
de7c1dc94b
@ -106,6 +106,12 @@ class defaultdict:
|
|||||||
return False
|
return False
|
||||||
return self._a == __o._a
|
return self._a == __o._a
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self._a)
|
||||||
|
|
||||||
|
def __contains__(self, key):
|
||||||
|
return key in self._a
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._a)
|
return len(self._a)
|
||||||
|
|
||||||
|
@ -1021,6 +1021,14 @@ inline void init_builtins(VM* _vm) {
|
|||||||
return VAR(self.contains(key));
|
return VAR(self.contains(key));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_vm->bind__iter__(_vm->tp_dict, [](VM* vm, PyObject* obj) {
|
||||||
|
Dict& self = _CAST(Dict&, obj);
|
||||||
|
auto items = self.items();
|
||||||
|
Tuple t(items.size());
|
||||||
|
for(int i=0; i<items.size(); i++) t[i] = items[i].first;
|
||||||
|
return vm->py_iter(VAR(std::move(t)));
|
||||||
|
});
|
||||||
|
|
||||||
_vm->bind_method<-1>("dict", "get", [](VM* vm, ArgsView args) {
|
_vm->bind_method<-1>("dict", "get", [](VM* vm, ArgsView args) {
|
||||||
Dict& self = _CAST(Dict&, args[0]);
|
Dict& self = _CAST(Dict&, args[0]);
|
||||||
if(args.size() == 1+1){
|
if(args.size() == 1+1){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user