mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-24 05:20:17 +00:00
adjust builtins
This commit is contained in:
parent
8267af74b5
commit
b52aa85f13
@ -21,6 +21,7 @@ def __str4split(self, sep):
|
|||||||
res.append(self)
|
res.append(self)
|
||||||
return res
|
return res
|
||||||
str.split = __str4split
|
str.split = __str4split
|
||||||
|
del __str4split
|
||||||
|
|
||||||
list.__repr__ = lambda self: '[' + ', '.join([repr(i) for i in self]) + ']'
|
list.__repr__ = lambda self: '[' + ', '.join([repr(i) for i in self]) + ']'
|
||||||
tuple.__repr__ = lambda self: '(' + ', '.join([repr(i) for i in self]) + ')'
|
tuple.__repr__ = lambda self: '(' + ', '.join([repr(i) for i in self]) + ')'
|
||||||
@ -29,6 +30,7 @@ def __list4extend(self, other):
|
|||||||
for i in other:
|
for i in other:
|
||||||
self.append(i)
|
self.append(i)
|
||||||
list.extend = __list4extend
|
list.extend = __list4extend
|
||||||
|
del __list4extend
|
||||||
|
|
||||||
def __list4__mul__(self, n):
|
def __list4__mul__(self, n):
|
||||||
a = []
|
a = []
|
||||||
@ -36,6 +38,7 @@ def __list4__mul__(self, n):
|
|||||||
a.extend(self)
|
a.extend(self)
|
||||||
return a
|
return a
|
||||||
list.__mul__ = __list4__mul__
|
list.__mul__ = __list4__mul__
|
||||||
|
del __list4__mul__
|
||||||
|
|
||||||
def __iterable4__eq__(self, other):
|
def __iterable4__eq__(self, other):
|
||||||
if len(self) != len(other):
|
if len(self) != len(other):
|
||||||
@ -46,6 +49,7 @@ def __iterable4__eq__(self, other):
|
|||||||
return True
|
return True
|
||||||
list.__eq__ = __iterable4__eq__
|
list.__eq__ = __iterable4__eq__
|
||||||
tuple.__eq__ = __iterable4__eq__
|
tuple.__eq__ = __iterable4__eq__
|
||||||
|
del __iterable4__eq__
|
||||||
|
|
||||||
def __iterable4__contains__(self, item):
|
def __iterable4__contains__(self, item):
|
||||||
for i in self:
|
for i in self:
|
||||||
@ -54,6 +58,7 @@ def __iterable4__contains__(self, item):
|
|||||||
return False
|
return False
|
||||||
list.__contains__ = __iterable4__contains__
|
list.__contains__ = __iterable4__contains__
|
||||||
tuple.__contains__ = __iterable4__contains__
|
tuple.__contains__ = __iterable4__contains__
|
||||||
|
del __iterable4__contains__
|
||||||
|
|
||||||
# https://github.com/python/cpython/blob/main/Objects/dictobject.c
|
# https://github.com/python/cpython/blob/main/Objects/dictobject.c
|
||||||
class dict:
|
class dict:
|
||||||
|
|||||||
4
src/vm.h
4
src/vm.h
@ -469,7 +469,7 @@ public:
|
|||||||
PyVar newModule(_Str name, bool saveToPath=true) {
|
PyVar newModule(_Str name, bool saveToPath=true) {
|
||||||
PyVar obj = newObject(_tp_module, (_Int)-2);
|
PyVar obj = newObject(_tp_module, (_Int)-2);
|
||||||
setAttr(obj, "__name__", PyStr(name));
|
setAttr(obj, "__name__", PyStr(name));
|
||||||
_modules[name] = obj;
|
if(saveToPath) _modules[name] = obj;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +607,7 @@ public:
|
|||||||
this->None = newObject(_types["NoneType"], (_Int)0);
|
this->None = newObject(_types["NoneType"], (_Int)0);
|
||||||
this->True = newObject(_tp_bool, true);
|
this->True = newObject(_tp_bool, true);
|
||||||
this->False = newObject(_tp_bool, false);
|
this->False = newObject(_tp_bool, false);
|
||||||
this->builtins = newModule("__builtins__");
|
this->builtins = newModule("builtins");
|
||||||
this->_main = newModule("__main__", false);
|
this->_main = newModule("__main__", false);
|
||||||
|
|
||||||
setAttr(_tp_type, __base__, _tp_object);
|
setAttr(_tp_type, __base__, _tp_object);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user