You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TextWrap vs words 1-character shorter than the width #45487
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/birkenfeld'closed_at=<Date2008-01-19.19:48:42.054>created_at=<Date2007-09-11.13:37:37.004>labels= ['type-bug']
title='TextWrap vs words 1-character shorter than the width'updated_at=<Date2008-01-19.19:48:42.053>user='https://bugs.python.org/sam'
>>> from textwrap import wrap
>>> wrap("foobarbaz reallylongwordgoeshere", width=10)
['foobarbaz r', 'eallylongw', 'ordgoesher', 'e']
>>> print [len(s) for s in _]
[11, 10, 10, 1]
This only seems to happen when the first word on the line is exactly one
character shorter than the width, and the next word is too long to fit,
so it is broken:
The bug is present in trunk and has been there since rev 33955. This
revision contained a fix to an infinite loop when indentation was set
longer than width with long word breaking enabled. In that case, it
would strip off at least one character on every pass. The fix was
however a bit too general, leading to the reported bug.
The added patch makes sure this doesn't happen anymore when indentation
isn't involved.
quentingallet-gilles commented on Sep 14, 2007
quentingallet-gillesmannequin
Mannequin
More actions
The previous patch is suboptimal and doesn't solve all cases. This one
does. My apologies.
Activity
sam commentedon Sep 11, 2007
This only seems to happen when the first word on the line is exactly one
character shorter than the width, and the next word is too long to fit,
so it is broken:
This is on Python 2.5, on Windows XP SP2.
quentingallet-gilles commentedon Sep 14, 2007
The bug is present in trunk and has been there since rev 33955. This
revision contained a fix to an infinite loop when indentation was set
longer than width with long word breaking enabled. In that case, it
would strip off at least one character on every pass. The fix was
however a bit too general, leading to the reported bug.
The added patch makes sure this doesn't happen anymore when indentation
isn't involved.
quentingallet-gilles commentedon Sep 14, 2007
The previous patch is suboptimal and doesn't solve all cases. This one
does. My apologies.
birkenfeld commentedon Sep 14, 2007
I'll look at this shortly.
quentingallet-gilles commentedon Jan 19, 2008
As i revisited this one for the Bug Day, I found I could optimize the
patch a little bit. Here's the updated diff.
Also... I think it's a good candidate for 2.5 maintenance release. Any
thoughts ?
birkenfeld commentedon Jan 19, 2008
Thanks for the patches, committed in r60093!