Commit 7902d9d2 authored by asaka's avatar asaka

allow unicode for module.__doc__, and allow recall module.__init__

parent 60bab2ea
...@@ -2143,14 +2143,21 @@ Box* typeMro(BoxedClass* self) { ...@@ -2143,14 +2143,21 @@ Box* typeMro(BoxedClass* self) {
Box* moduleInit(BoxedModule* self, Box* name, Box* doc) { Box* moduleInit(BoxedModule* self, Box* name, Box* doc) {
RELEASE_ASSERT(PyModule_Check(self), ""); RELEASE_ASSERT(PyModule_Check(self), "");
RELEASE_ASSERT(name->cls == str_cls, ""); RELEASE_ASSERT(name->cls == str_cls, "");
RELEASE_ASSERT(!doc || doc->cls == str_cls, ""); RELEASE_ASSERT(!doc || doc->cls == str_cls || doc->cls == unicode_cls, "");
doc = doc ? doc : None;
HCAttrs* attrs = self->getHCAttrsPtr(); HCAttrs* attrs = self->getHCAttrsPtr();
RELEASE_ASSERT(attrs->hcls->attributeArraySize() == 0, "");
if (attrs->hcls->attributeArraySize() == 0) {
attrs->hcls = HiddenClass::makeSingleton(); attrs->hcls = HiddenClass::makeSingleton();
self->giveAttr("__name__", name); self->giveAttr("__name__", name);
self->giveAttr("__doc__", doc ? doc : boxString("")); self->giveAttr("__doc__", doc);
} else {
self->setattr(internStringMortal("__name__"), name, NULL);
self->setattr(internStringMortal("__doc__"), doc, NULL);
}
return None; return None;
} }
......
import empty_module import empty_module
import math import math
import types
x = repr(empty_module) x = repr(empty_module)
...@@ -9,3 +10,12 @@ print x[0:29] ...@@ -9,3 +10,12 @@ print x[0:29]
print x[-2:] print x[-2:]
print repr(math)[:10] print repr(math)[:10]
m = types.ModuleType("foo")
print m.__doc__, type(m.__doc__)
m = types.ModuleType("foo", "bar")
print m.__doc__, type(m.__doc__)
m = types.ModuleType("foo", u"bar")
print m.__doc__, type(m.__doc__)
m.__init__("bar", "baz")
print m.__doc__, type(m.__doc__)
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