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: argparse help formatter does not honor non-breaking space
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, bethard, chris.jerdonek, paul.j3, peter.otten, roysmith, serhiy.storchaka, shihai1991, xiang.zhang
Priority: normal Keywords:

Created on 2012-12-05 22:03 by roysmith, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (9)
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.
msg354188 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2019-10-08 11:49
I checked the help format.
the help_lines' width in python2.7 is different python3.

The width is more likely a hardcode in 
https://github.com/python/cpython/blob/2.7/Lib/argparse.py#L165.
, so the help_lines = [u'This is a very long help string. ex: "--s3', u's3://my.bucket/dir1/dir2"'](when joining this help_lines it will add a '\n' in the middle)

Since python 3.3, the width is a dynamic value in 
https://github.com/python/cpython/blob/master/Lib/argparse.py#L170
, so the help_lines = ['This is a very long help string. ex: "--s3\xa0s3://my.bucket/dir1/dir2"']
msg354190 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2019-10-08 11:52
oh, typo error. the help_lines' width in python2.7 is different python3.-->the help_lines' width in python2.7 is different with python3.x
msg372092 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-06-22 14:53
Python 2 is EOL, so I think this issue should be closed.
msg372413 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-06-26 08:15
> Python 2 is EOL, so I think this issue should be closed.

+1, if someone need create a PR, we can reopen it again.
History
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 60827
2020-06-26 09:12:12cheryl.sabellasetstatus: open -> closed
resolution: out of date
stage: needs patch -> resolved
2020-06-26 08:15:12shihai1991setmessages: + msg372413
2020-06-22 14:53:54ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg372092
2019-10-08 11:52:00shihai1991setmessages: + msg354190
2019-10-08 11:49:22shihai1991setnosy: + shihai1991
messages: + msg354188
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 -> (no value)
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