Commit 1d1236b2 authored by Marius Wachtler's avatar Marius Wachtler

Merge pull request #1170 from Daetalus/numpy_update

some minor NumPy fixing
parents da8686b1 64bc9769
......@@ -1397,7 +1397,7 @@ extern "C" BORROWED(PyObject*) PyEval_GetGlobals(void) noexcept {
}
extern "C" BORROWED(PyObject*) PyEval_GetBuiltins(void) noexcept {
return builtins_module;
return builtins_module->getAttrWrapper();
}
Box* ellipsisRepr(Box* self) {
......
......@@ -1164,6 +1164,13 @@ extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
return rtn;
}
Box* strRMod(BoxedString* lhs, Box* rhs) {
Box* rtn = PyString_Format(rhs, lhs);
if (!rtn)
throwCAPIException();
return rtn;
}
extern "C" Box* strMul(BoxedString* lhs, Box* rhs) {
assert(PyString_Check(lhs));
......@@ -2926,6 +2933,7 @@ void setupStr() {
str_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)strAdd, UNKNOWN, 2)));
str_cls->giveAttr("__mod__", new BoxedFunction(FunctionMetadata::create((void*)strMod, UNKNOWN, 2)));
str_cls->giveAttr("__rmod__", new BoxedFunction(FunctionMetadata::create((void*)strRMod, UNKNOWN, 2)));
str_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)strMul, UNKNOWN, 2)));
// TODO not sure if this is right in all cases:
str_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)strMul, UNKNOWN, 2)));
......
......@@ -1561,6 +1561,12 @@ static Box* builtinFunctionOrMethodName(Box* b, void*) {
return incref(func->name);
}
static Box* wrapperobjectName(Box* w, void*) {
assert(w->cls == wrapperobject_cls);
BoxedWrapperObject* wrapper_obj = static_cast<BoxedWrapperObject*>(w);
return boxString(wrapper_obj->descr->wrapper->name);
}
static Box* functionCode(Box* self, void*) {
assert(self->cls == function_cls);
BoxedFunction* func = static_cast<BoxedFunction*>(self);
......@@ -2956,9 +2962,7 @@ static PyObject* object_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
builtins = PyEval_GetBuiltins();
if (builtins == NULL)
goto error;
// Pyston change: builtins is a module not a dict
// sorted = PyDict_GetItemString(builtins, "sorted");
sorted = builtins->getattr(autoDecref(internStringMortal("sorted")));
sorted = PyDict_GetItemString(builtins, "sorted");
if (sorted == NULL)
goto error;
sorted_methods = PyObject_CallFunctionObjArgs(sorted, abstract_methods, NULL);
......@@ -4499,6 +4503,8 @@ void setupRuntime() {
instancemethod_cls->giveAttr("im_class", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT,
offsetof(BoxedInstanceMethod, im_class), true));
wrapperobject_cls->giveAttrDescriptor("__name__", wrapperobjectName, NULL);
slice_cls->giveAttr(
"__new__",
new BoxedFunction(FunctionMetadata::create((void*)sliceNew, UNKNOWN, 4, false, false), { NULL, None }));
......
......@@ -215,3 +215,9 @@ for i in xrange(-8, 8):
print i,j, repr(s[i:j])
for k in (-2, 1, 1, 2):
print i,j,k, repr(s[i:j:k]), repr(s[slice(i, j, k)])
class D(str):
pass
print(D('abc').__rmod__('%s'))
......@@ -5,5 +5,6 @@ print type(C).__str__ is object.__str__
print type(None).__str__ is object.__str__
print type(None).__str__ is None.__str__
print type(None.__str__)
print(None.__str__.__name__)
print type(type(None).__str__.__get__(None, type(None)))
print u"".__len__.__call__()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment