From fbf2786c4c89430e2067016603078cf3500cfe94 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 15 Apr 2020 23:00:20 +0300 Subject: bpo-40257: Output object's own docstring in pydoc (GH-19479) --- Lib/pydoc.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'Lib/pydoc.py') diff --git a/Lib/pydoc.py b/Lib/pydoc.py index f172700a15..a89b804570 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -825,11 +825,8 @@ class HTMLDoc(Doc): push(msg) for name, kind, homecls, value in ok: base = self.docother(getattr(object, name), name, mod) - if callable(value) or inspect.isdatadescriptor(value): - doc = getattr(value, "__doc__", None) - else: - doc = None - if doc is None: + doc = getdoc(value) + if not doc: push('
%s
\n' % base) else: doc = self.markup(getdoc(value), self.preformat, @@ -1309,10 +1306,7 @@ location listed above. hr.maybe() push(msg) for name, kind, homecls, value in ok: - if callable(value) or inspect.isdatadescriptor(value): - doc = getdoc(value) - else: - doc = None + doc = getdoc(value) try: obj = getattr(object, name) except AttributeError: @@ -1448,7 +1442,9 @@ location listed above. chop = maxlen - len(line) if chop < 0: repr = repr[:chop] + '...' line = (name and self.bold(name) + ' = ' or '') + repr - if doc is not None: + if not doc: + doc = getdoc(object) + if doc: line += '\n' + self.indent(str(doc)) return line @@ -1672,7 +1668,8 @@ def render_doc(thing, title='Python Library Documentation: %s', forceload=0, if not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or - inspect.isdatadescriptor(object)): + inspect.isdatadescriptor(object) or + inspect.getdoc(object)): # If the passed object is a piece of data or an instance, # document its available methods instead of its value. object = type(object) -- cgit v1.2.1