mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
#15510: clarify textwrap's handling of whitespace, and add confirming tests.
Patch by Chris Jerdonek.
This commit is contained in:
parent
b676727dca
commit
1b6e7c47f2
2 changed files with 68 additions and 13 deletions
|
@ -26,6 +26,9 @@ otherwise, you should use an instance of :class:`TextWrapper` for efficiency.
|
|||
Optional keyword arguments correspond to the instance attributes of
|
||||
:class:`TextWrapper`, documented below. *width* defaults to ``70``.
|
||||
|
||||
See the :meth:`TextWrapper.wrap` method for additional details on how
|
||||
:func:`wrap` behaves.
|
||||
|
||||
|
||||
.. function:: fill(text[, width[, ...]])
|
||||
|
||||
|
@ -134,9 +137,11 @@ indentation from strings that have unwanted whitespace to the left of the text.
|
|||
|
||||
.. attribute:: drop_whitespace
|
||||
|
||||
(default: ``True``) If true, whitespace that, after wrapping, happens to
|
||||
end up at the beginning or end of a line is dropped (leading whitespace in
|
||||
the first line is always preserved, though).
|
||||
(default: ``True``) If true, whitespace at the beginning and ending of
|
||||
every line (after wrapping but before indenting) is dropped.
|
||||
Whitespace at the beginning of the paragraph, however, is not dropped
|
||||
if non-whitespace follows it. If whitespace being dropped takes up an
|
||||
entire line, the whole line is dropped.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
Whitespace was always dropped in earlier versions.
|
||||
|
@ -145,7 +150,8 @@ indentation from strings that have unwanted whitespace to the left of the text.
|
|||
.. attribute:: initial_indent
|
||||
|
||||
(default: ``''``) String that will be prepended to the first line of
|
||||
wrapped output. Counts towards the length of the first line.
|
||||
wrapped output. Counts towards the length of the first line. The empty
|
||||
string is not indented.
|
||||
|
||||
|
||||
.. attribute:: subsequent_indent
|
||||
|
@ -208,8 +214,9 @@ indentation from strings that have unwanted whitespace to the left of the text.
|
|||
|
||||
Wraps the single paragraph in *text* (a string) so every line is at most
|
||||
:attr:`width` characters long. All wrapping options are taken from
|
||||
instance attributes of the :class:`TextWrapper` instance. Returns a list
|
||||
of output lines, without final newlines.
|
||||
instance attributes of the :class:`TextWrapper` instance. Returns a list
|
||||
of output lines, without final newlines. If the wrapped output has no
|
||||
content, the returned list is empty.
|
||||
|
||||
|
||||
.. method:: fill(text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue