Issue 16623: argparse help formatter does not honor non-breaking space (original) (raw)

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:39 admin set github: 60827
2020-06-26 09:12:12 cheryl.sabella set status: open -> closedresolution: out of datestage: needs patch -> resolved
2020-06-26 08:15:12 shihai1991 set messages: +
2020-06-22 14:53:54 ZackerySpytz set nosy: + ZackerySpytzmessages: +
2019-10-08 11:52:00 shihai1991 set messages: +
2019-10-08 11:49:22 shihai1991 set nosy: + shihai1991messages: +
2017-01-17 14:08:56 peter.otten set nosy: + peter.otten
2017-01-17 06:48:49 BreamoreBoy set nosy: - BreamoreBoy
2017-01-17 06:13:07 xiang.zhang set status: closed -> opensuperseder: argparse breaks long lines on NO-BREAK SPACE -> nosy: + serhiy.storchakamessages: + resolution: fixed -> (no value)stage: resolved -> needs patch
2017-01-17 06:09:25 xiang.zhang set status: open -> closedsuperseder: argparse breaks long lines on NO-BREAK SPACEnosy: + xiang.zhangmessages: + resolution: fixedstage: resolved
2014-07-13 23:58:05 paul.j3 set messages: +
2014-07-13 14:26:49 BreamoreBoy set nosy: + paul.j3, BreamoreBoymessages: +
2012-12-08 05:40:12 terry.reedy set nosy: + bethard
2012-12-05 23:22:49 chris.jerdonek set nosy: + chris.jerdonek
2012-12-05 22:03:21 roysmith create