Skip to content

Commit

Permalink
Added __doc__ attribute (alias func_doc), initialized from first
Browse files Browse the repository at this point in the history
constant in code object if it is a string, else None
  • Loading branch information
gvanrossum committed Jan 7, 1995
1 parent 8b14b4c commit 5bd3805
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,26 @@ newfuncobject(code, globals)
{
funcobject *op = NEWOBJ(funcobject, &Functype);
if (op != NULL) {
object *doc;
object *consts;
INCREF(code);
op->func_code = code;
INCREF(globals);
op->func_globals = globals;
op->func_name = ((codeobject*)(op->func_code))->co_name;
op->func_name = ((codeobject *)code)->co_name;
INCREF(op->func_name);
op->func_argcount = -1; /* Unknown */
op->func_argdefs = NULL; /* No default arguments */
consts = ((codeobject *)code)->co_consts;
if (gettuplesize(consts) >= 1) {
doc = gettupleitem(consts, 0);
if (!is_stringobject(doc))
doc = None;
}
else
doc = None;
INCREF(doc);
op->func_doc = doc;
}
return (object *)op;
}
Expand Down Expand Up @@ -117,6 +129,8 @@ static struct memberlist func_memberlist[] = {
{"func_name", T_OBJECT, OFF(func_name), READONLY},
{"func_argcount",T_INT, OFF(func_argcount), READONLY},
{"func_argdefs",T_OBJECT, OFF(func_argdefs), READONLY},
{"func_doc", T_OBJECT, OFF(func_doc)},
{"__doc__", T_OBJECT, OFF(func_doc)},
{NULL} /* Sentinel */
};

Expand All @@ -135,6 +149,7 @@ func_dealloc(op)
DECREF(op->func_code);
DECREF(op->func_globals);
XDECREF(op->func_argdefs);
XDECREF(op->func_doc);
DEL(op);
}

Expand Down

0 comments on commit 5bd3805

Please sign in to comment.