classification
Title: argparse help formatter does not honor non-breaking space
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: bethard, chris.jerdonek, paul.j3, peter.otten, roysmith, serhiy.storchaka, xiang.zhang
Priority: normal Keywords:

Created on 2012-12-05 22:03 by roysmith, last changed 2017-01-17 14:08 by peter.otten.

Messages (5)
msg177012 - (view) Author: Roy Smith (roysmith) Date: 2012-12-05 22:03
Running this code:

---------------------------------------
import argparse

p = argparse.ArgumentParser()
p.add_argument('--foo',
               help=u'This is a very long help string.  ex: "--s3\u00A0s3://my.bucket/dir1/dir2"')
p.parse_args()
---------------------------------------

produces:

---------------------------------------
$ ./arg.py  --help
usage: arg.py [-h] [--foo FOO]

optional arguments:
  -h, --help  show this help message and exit
  --foo FOO   This is a very long help string. ex: "--s3
              s3://my.bucket/dir1/dir2"
---------------------------------------

It should not be breaking the line at a non-breaking space.  I'm running:

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
msg222931 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-13 14:26
The example code works fine using 3.4.1 and 3.5.0a0 on Windows 7.
msg222981 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2014-07-13 23:58
The issue here is how `textwrap` handles the non-breaking space.  That's being address here:

http://bugs.python.org/issue20491 textwrap: Non-breaking space not honored

Temporarily an `argparse` user can get around it with `formatter_class=argparse.RawTextHelpFormatter`.  That suppresses all automatic wrapping, so it's not perfect.
msg285612 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-01-17 06:09
#29290 reports the same problem as here.
msg285613 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-01-17 06:13
Ahh, sorry. I made a mistake. It's not the same as 29290. This is about 2.7. Although #20491 is closed but 2.7 seems not patched. Nosy Serhiy.
History
Date User Action Args
2017-01-17 14:08:56peter.ottensetnosy: + peter.otten
2017-01-17 06:48:49BreamoreBoysetnosy: - BreamoreBoy
2017-01-17 06:13:07xiang.zhangsetstatus: closed -> open

superseder: argparse breaks long lines on NO-BREAK SPACE ->

nosy: + serhiy.storchaka
messages: + msg285613
resolution: fixed ->
stage: resolved -> needs patch
2017-01-17 06:09:25xiang.zhangsetstatus: open -> closed

superseder: argparse breaks long lines on NO-BREAK SPACE

nosy: + xiang.zhang
messages: + msg285612
resolution: fixed
stage: resolved
2014-07-13 23:58:05paul.j3setmessages: + msg222981
2014-07-13 14:26:49BreamoreBoysetnosy: + paul.j3, BreamoreBoy
messages: + msg222931
2012-12-08 05:40:12terry.reedysetnosy: + bethard
2012-12-05 23:22:49chris.jerdoneksetnosy: + chris.jerdonek
2012-12-05 22:03:21roysmithcreate