mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Use getdoc(object) instead of object.__doc__ to fix indentation problems.
Thanks to Robert Dick <dickrp@ece.northwestern.edu> for reporting this bug and submitting a patch. Adjust doc(object) to display useful documentation for plain values (e.g. help([]) now shows the methods on the list instead of just printing "[]"). (This change has been tested interactively, by generating docs for the standard library, and by running the module documentation webserver.)
This commit is contained in:
parent
3c24d96bc5
commit
bba6acc714
1 changed files with 10 additions and 2 deletions
12
Lib/pydoc.py
12
Lib/pydoc.py
|
@ -886,7 +886,7 @@ class HTMLDoc(Doc):
|
||||||
if name:
|
if name:
|
||||||
push('<dl><dt><strong>%s</strong></dt>\n' % name)
|
push('<dl><dt><strong>%s</strong></dt>\n' % name)
|
||||||
if value.__doc__ is not None:
|
if value.__doc__ is not None:
|
||||||
doc = self.markup(value.__doc__, self.preformat)
|
doc = self.markup(getdoc(value), self.preformat)
|
||||||
push('<dd><tt>%s</tt></dd>\n' % doc)
|
push('<dd><tt>%s</tt></dd>\n' % doc)
|
||||||
push('</dl>\n')
|
push('</dl>\n')
|
||||||
|
|
||||||
|
@ -1160,7 +1160,7 @@ class TextDoc(Doc):
|
||||||
push(msg)
|
push(msg)
|
||||||
for name, kind, homecls, value in ok:
|
for name, kind, homecls, value in ok:
|
||||||
if callable(value) or inspect.isdatadescriptor(value):
|
if callable(value) or inspect.isdatadescriptor(value):
|
||||||
doc = getattr(value, "__doc__", None)
|
doc = getdoc(value)
|
||||||
else:
|
else:
|
||||||
doc = None
|
doc = None
|
||||||
push(self.docother(getattr(object, name),
|
push(self.docother(getattr(object, name),
|
||||||
|
@ -1454,6 +1454,14 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0):
|
||||||
desc += ' in ' + name[:name.rfind('.')]
|
desc += ' in ' + name[:name.rfind('.')]
|
||||||
elif module and module is not object:
|
elif module and module is not object:
|
||||||
desc += ' in module ' + module.__name__
|
desc += ' in module ' + module.__name__
|
||||||
|
if not (inspect.ismodule(object) or
|
||||||
|
inspect.isclass(object) or
|
||||||
|
inspect.isroutine(object) or
|
||||||
|
isinstance(object, property)):
|
||||||
|
# If the passed object is a piece of data or an instance,
|
||||||
|
# document its available methods instead of its value.
|
||||||
|
object = type(object)
|
||||||
|
desc += ' object'
|
||||||
pager(title % desc + '\n\n' + text.document(object, name))
|
pager(title % desc + '\n\n' + text.document(object, name))
|
||||||
except (ImportError, ErrorDuringImport), value:
|
except (ImportError, ErrorDuringImport), value:
|
||||||
print value
|
print value
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue