mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
bpo-40257: Output object's own docstring in pydoc (GH-19479)
This commit is contained in:
parent
ba1bcffe5c
commit
fbf2786c4c
7 changed files with 61 additions and 32 deletions
19
Lib/pydoc.py
19
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('<dl><dt>%s</dl>\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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue