Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,17 @@ def indent(self, text, prefix=' '):
lines = [(prefix + line).rstrip() for line in text.split('\n')]
return '\n'.join(lines)

def _format_doc(self, text, width=68):
"""Wraps the single-line summary if it is too long."""
if not text: return ''
lines = text.split('\n', 2)
if len(lines) > 1 and lines[1]:
return text
lines[:1] = textwrap.wrap(lines[0], width,
break_long_words=False,
break_on_hyphens=False)
return '\n'.join(lines)

def section(self, title, contents):
"""Format a section with a given heading."""
clean_contents = self.indent(contents).rstrip()
Expand Down Expand Up @@ -1390,6 +1401,7 @@ def makename(c, m=object.__module__):

doc = getdoc(object)
if doc:
doc = self._format_doc(doc)
push(doc + '\n')

# List the mro, if non-trivial.
Expand Down Expand Up @@ -1590,6 +1602,7 @@ def docroutine(self, object, name=None, mod=None, cl=None, homecls=None):
return decl + '\n'
else:
doc = getdoc(object) or ''
doc = self._format_doc(doc)
return decl + '\n' + (doc and self.indent(doc).rstrip() + '\n')

def docdata(self, object, name=None, mod=None, cl=None, *ignored):
Expand All @@ -1602,6 +1615,7 @@ def docdata(self, object, name=None, mod=None, cl=None, *ignored):
push('\n')
doc = getdoc(object) or ''
if doc:
doc = self._format_doc(doc)
push(self.indent(doc))
push('\n')
return ''.join(results)
Expand All @@ -1620,7 +1634,8 @@ def docother(self, object, name=None, mod=None, parent=None, *ignored,
if not doc:
doc = getdoc(object)
if doc:
line += '\n' + self.indent(str(doc)) + '\n'
doc = self._format_doc(str(doc))
line += '\n' + self.indent(doc) + '\n'
return line

class _PlainTextDoc(TextDoc):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`pydoc` now wraps long single-line summary in text output.
Loading