This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inconsistent results of leading whitespace in textwrap input
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gward Nosy List: gvanrossum, gward, r.david.murray
Priority: normal Keywords:

Created on 2002-10-14 05:00 by r.david.murray, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (4)
msg12772 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2002-10-14 05:00
>>> x = TextWrapper()       
>>> x.wrap('This is a sentence that will not wrap')
['This is a sentence that will not wrap']
>>> x.wrap('  This is a sentence that will not wrap')
['  This is a sentence that will not wrap']
>>> x.wrap('This is a sentence that will wrap because I have added a bunch of words to it until it is longer than 70 chars.')
['This is a sentence that will wrap because I have added a bunch of', 'words to it until it is longer than 70 chars.']
>>> x.wrap('  This is a sentence that will wrap because I have added a bunch of words to it until it is longer than 70 chars.')
['This is a sentence that will wrap because I have added a bunch of', 'words to it until it is longer than 70 chars.']

To me, this looks like a bug.  It violates POLA, anyway (took me a while
to figure out why one paragraph and only one paragraph in my output
was indented more than the rest).
msg12773 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-10-14 23:54
Logged In: YES 
user_id=6380

You always want the leading space to disappear, right?

Then the easiest fix is to get rid of an optimization in wrap():

delete these two lines

        if len(text) + len(indent) <= self.width:
            return [indent + text]
msg12774 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2002-10-15 00:21
Logged In: YES 
user_id=100308

I don't care which it does, as long as it is consistent.  And
whichever it does probably ought to be documented <grin>.
msg12775 - (view) Author: Greg Ward (gward) (Python committer) Date: 2002-12-09 16:27
Logged In: YES 
user_id=14422

Fixed in rev 1.20 of textwrap.py; tested in rev 1.17 of
test/test_textwrap.py.
History
Date User Action Args
2022-04-10 16:05:45adminsetgithub: 37321
2002-10-14 05:00:46rdmurraycreate