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: textwrap has problems wrapping hyphens
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gward Nosy List: goodger, gward
Priority: normal Keywords:

Created on 2002-08-17 14:46 by goodger, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (5)
msg12039 - (view) Author: David Goodger (goodger) (Python committer) Date: 2002-08-17 14:46
(Greg already knows about this from private mail; 
this makes it "official".)

Long multi-word command-line options (begin 
with "--" and contain internal "-") inside text may be 
wrapped badly by textwrap.  For example, "--an-
option" may become "--\nan-option" or "--an-\
noption".  Perhaps words that begin with hyphens 
should not be wrapped at all?
msg12040 - (view) Author: Greg Ward (gward) (Python committer) Date: 2002-08-22 21:04
Logged In: YES 
user_id=14422

Thanks for the reminder, David!

Fixed in Lib/textwrap.py rev 1.14.
msg12041 - (view) Author: David Goodger (goodger) (Python committer) Date: 2002-08-25 14:29
Logged In: YES 
user_id=7733

There's still an edge case that gives poor results.  Try 
wrapping "--text--.".  It will wrap like "--text/--/.", leaving 
just the period (".") or the dashes & period ("--.") on the 
next line.  The latter may or may not be a problem, but 
I'd say wrapping just the sentence-ending period 
definitely *is* a problem.

A more plausible example is "what the--.".
msg12042 - (view) Author: David Goodger (goodger) (Python committer) Date: 2002-09-12 02:06
Logged In: YES 
user_id=7733

More edge cases came up today.  These break at the 
slashes:

    "(--option)" --> "(/--/option)"

    "(--option-opt)" --> "(/--option-/opt)"

All but the last of these breaks are bad.

Perhaps TextWrapper should have a 
"break_whitespace_only" option?  This would be 
especially useful for technical text, where breaks at 
hyphens may change the text's meaning.
msg12043 - (view) Author: Greg Ward (gward) (Python committer) Date: 2003-05-07 01:21
Logged In: YES 
user_id=14422

Finally!  Fixed in rev 1.26 of Lib/textwrap.py, with tests
in rev 1.21 of Lib/test/test_textwrap.py.
History
Date User Action Args
2022-04-10 16:05:36adminsetgithub: 37049
2002-08-17 14:46:32goodgercreate