Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a92c62

Browse files
committed
New feature: if the object's type has a non-NULL tp_doc field, that
is returned as the object's __doc__ attribute. (If only the list of methods would be referenced from the type...)
1 parent 73d8bff commit 8a92c62

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Objects/methodobject.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,15 @@ Py_FindMethodInChain(chain, self, name)
250250
PyObject *self;
251251
char *name;
252252
{
253-
if (strcmp(name, "__methods__") == 0)
254-
return listmethodchain(chain);
253+
if (name[0] == '_' && name[1] == '_') {
254+
if (strcmp(name, "__methods__") == 0)
255+
return listmethodchain(chain);
256+
if (strcmp(name, "__doc__") == 0) {
257+
char *doc = self->ob_type->tp_doc;
258+
if (doc != NULL)
259+
return PyString_FromString(doc);
260+
}
261+
}
255262
while (chain != NULL) {
256263
PyMethodDef *ml = chain->methods;
257264
for (; ml->ml_name != NULL; ml++) {

0 commit comments

Comments
 (0)