[Python-bugs-list] [ python-Bugs-622849 ] inconsistent results of leading whitespace in textwrap input

noreply@sourceforge.net noreply@sourceforge.net
Mon, 14 Oct 2002 17:21:41 -0700


Bugs item #622849, was opened at 2002-10-13 21:00
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=622849&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: R. David Murray (rdmurray)
Assigned to: Greg Ward (gward)
Summary: inconsistent results of leading whitespace in textwrap input

Initial Comment:
>>> 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).


----------------------------------------------------------------------

>Comment By: R. David Murray (rdmurray)
Date: 2002-10-14 16:21

Message:
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>.


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-10-14 15:54

Message:
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]


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=622849&group_id=5470