Commit bfb0ec4a authored by Kevin Modzelewski's avatar Kevin Modzelewski

Now that object has __doc__, fix others

Otherwise they would inherit object's __doc__
parent 754ddae3
......@@ -636,6 +636,10 @@ void BoxedClass::freeze() {
assert(!is_constant);
assert(tp_name); // otherwise debugging will be very hard
auto doc_str = getStaticString("__doc__");
if (!hasattr(doc_str))
giveAttr(incref(doc_str), boxString(tp_name));
fixup_slot_dispatchers(this);
if (instancesHaveDictAttrs() || instancesHaveHCAttrs()) {
......
......@@ -1791,6 +1791,17 @@ static Box* functionNonzero(BoxedFunction* self) {
Py_RETURN_TRUE;
}
static Box* im_doc(Box* b, void*) noexcept {
RELEASE_ASSERT(b->cls == instancemethod_cls, "");
auto doc_str = getStaticString("__doc__");
try {
return getattr(static_cast<BoxedInstanceMethod*>(b)->func, doc_str);
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
}
}
extern "C" {
Box* Py_None = NULL;
Box* NotImplemented = NULL;
......@@ -4234,7 +4245,10 @@ void setupRuntime() {
none_cls->giveAttr("__base__", object_cls);
Py_INCREF(Py_None);
object_cls->giveAttr("__base__", Py_None);
object_cls->giveAttr("__doc__", boxString("The most base type"));
type_cls->giveAttr("__doc__",
boxString("type(object) -> the object's type\ntype(name, bases, dict) -> a new type"));
// Not sure why CPython defines sizeof(PyTupleObject) to include one element,
// but we copy that, which means we have to subtract that extra pointer to get the tp_basicsize:
......@@ -4574,10 +4588,14 @@ void setupRuntime() {
instancemethod_cls->giveAttrBorrowed("__func__", instancemethod_cls->getattr(getStaticString("im_func")));
instancemethod_cls->giveAttrMember("im_self", T_OBJECT, offsetof(BoxedInstanceMethod, obj));
instancemethod_cls->giveAttrBorrowed("__self__", instancemethod_cls->getattr(getStaticString("im_self")));
instancemethod_cls->freeze();
instancemethod_cls->giveAttrMember("im_class", T_OBJECT, offsetof(BoxedInstanceMethod, im_class), true);
// TODO: this should be handled via a getattro instead (which proxies to the function):
instancemethod_cls->giveAttrDescriptor("__doc__", im_doc, NULL);
instancemethod_cls->freeze();
slice_cls->giveAttr("__new__",
new BoxedFunction(BoxedCode::create((void*)sliceNew, UNKNOWN, 4, false, false, "slice.__new__"),
{ NULL, Py_None }));
......
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