adjust builtins

This commit is contained in:
blueloveTH 2022-11-10 16:00:21 +08:00
parent 8267af74b5
commit b52aa85f13
2 changed files with 7 additions and 2 deletions

View File

@ -21,6 +21,7 @@ def __str4split(self, sep):
res.append(self)
return res
str.split = __str4split
del __str4split
list.__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:
self.append(i)
list.extend = __list4extend
del __list4extend
def __list4__mul__(self, n):
a = []
@ -36,6 +38,7 @@ def __list4__mul__(self, n):
a.extend(self)
return a
list.__mul__ = __list4__mul__
del __list4__mul__
def __iterable4__eq__(self, other):
if len(self) != len(other):
@ -46,6 +49,7 @@ def __iterable4__eq__(self, other):
return True
list.__eq__ = __iterable4__eq__
tuple.__eq__ = __iterable4__eq__
del __iterable4__eq__
def __iterable4__contains__(self, item):
for i in self:
@ -54,6 +58,7 @@ def __iterable4__contains__(self, item):
return False
list.__contains__ = __iterable4__contains__
tuple.__contains__ = __iterable4__contains__
del __iterable4__contains__
# https://github.com/python/cpython/blob/main/Objects/dictobject.c
class dict:

View File

@ -469,7 +469,7 @@ public:
PyVar newModule(_Str name, bool saveToPath=true) {
PyVar obj = newObject(_tp_module, (_Int)-2);
setAttr(obj, "__name__", PyStr(name));
_modules[name] = obj;
if(saveToPath) _modules[name] = obj;
return obj;
}
@ -607,7 +607,7 @@ public:
this->None = newObject(_types["NoneType"], (_Int)0);
this->True = newObject(_tp_bool, true);
this->False = newObject(_tp_bool, false);
this->builtins = newModule("__builtins__");
this->builtins = newModule("builtins");
this->_main = newModule("__main__", false);
setAttr(_tp_type, __base__, _tp_object);