Commit fe918ed5 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Better to set __doc__ here

parent 3b485047
......@@ -1668,19 +1668,13 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
// It'd be ok to add __doc__ to the dict multiple times, since the last one would win
if (written_names.count("__doc__") == 0) {
bool found_docstr = false;
if (body.size() && body[0]->type == AST_TYPE::Expr) {
AST_Expr* first_expr = ast_cast<AST_Expr>(body[0]);
if (first_expr->value->type == AST_TYPE::Str) {
found_docstr = true;
rtn_dict->keys.push_back(new AST_Str("__doc__"));
rtn_dict->values.push_back(first_expr->value);
}
}
if (!found_docstr) {
rtn_dict->keys.push_back(new AST_Str("__doc__"));
rtn_dict->values.push_back(makeName("None", AST_TYPE::Load));
}
}
// Even if the user never explicitly wrote to __module__, there was an
......
......@@ -313,6 +313,10 @@ extern "C" Box* createUserClass(std::string* name, Box* _base, Box* _attr_dict)
made->giveAttr(static_cast<BoxedString*>(p.first)->s, p.second);
}
if (made->getattr("__doc__") == NULL) {
made->giveAttr("__doc__", None);
}
// Note: make sure to do this after assigning the attrs, since it will overwrite any defined __name__
made->setattr("__name__", boxString(*name), NULL);
......
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