Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse help formatter does not honor non-breaking space #60827

Closed
roysmith mannequin opened this issue Dec 5, 2012 · 9 comments
Closed

argparse help formatter does not honor non-breaking space #60827

roysmith mannequin opened this issue Dec 5, 2012 · 9 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@roysmith
Copy link
Mannequin

roysmith mannequin commented Dec 5, 2012

BPO 16623
Nosy @cjerdonek, @serhiy-storchaka, @zhangyangyu, @ZackerySpytz, @shihai1991

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 = None
closed_at = <Date 2020-06-26.09:12:12.028>
created_at = <Date 2012-12-05.22:03:21.564>
labels = ['type-bug', 'library']
title = 'argparse help formatter does not honor non-breaking space'
updated_at = <Date 2020-06-26.09:12:12.027>
user = 'https://bugs.python.org/roysmith'

bugs.python.org fields:

activity = <Date 2020-06-26.09:12:12.027>
actor = 'cheryl.sabella'
assignee = 'none'
closed = True
closed_date = <Date 2020-06-26.09:12:12.028>
closer = 'cheryl.sabella'
components = ['Library (Lib)']
creation = <Date 2012-12-05.22:03:21.564>
creator = 'roysmith'
dependencies = []
files = []
hgrepos = []
issue_num = 16623
keywords = []
message_count = 9.0
messages = ['177012', '222931', '222981', '285612', '285613', '354188', '354190', '372092', '372413']
nosy_count = 9.0
nosy_names = ['roysmith', 'peter.otten', 'bethard', 'chris.jerdonek', 'paul.j3', 'serhiy.storchaka', 'xiang.zhang', 'ZackerySpytz', 'shihai1991']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue16623'
versions = ['Python 2.7']

@roysmith
Copy link
Mannequin Author

roysmith mannequin commented Dec 5, 2012

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

@roysmith roysmith mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 5, 2012
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Jul 13, 2014

The example code works fine using 3.4.1 and 3.5.0a0 on Windows 7.

@paulj3
Copy link
Mannequin

paulj3 mannequin commented Jul 13, 2014

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.

@zhangyangyu
Copy link
Member

bpo-29290 reports the same problem as here.

@zhangyangyu
Copy link
Member

Ahh, sorry. I made a mistake. It's not the same as 29290. This is about 2.7. Although bpo-20491 is closed but 2.7 seems not patched. Nosy Serhiy.

@zhangyangyu zhangyangyu reopened this Jan 17, 2017
@shihai1991
Copy link
Member

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"']

@shihai1991
Copy link
Member

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

@ZackerySpytz
Copy link
Mannequin

ZackerySpytz mannequin commented Jun 22, 2020

Python 2 is EOL, so I think this issue should be closed.

@shihai1991
Copy link
Member

Python 2 is EOL, so I think this issue should be closed.

+1, if someone need create a PR, we can reopen it again.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants