You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
argparse.RawTextHelpFormatter does not maintain lines separated by more than one newline #75511
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=Noneclosed_at=<Date2017-09-07.23:18:33.574>created_at=<Date2017-09-02.03:19:37.683>labels= ['3.7', 'library']
title='argparse.RawTextHelpFormatter does not maintain lines separated by more than one newline'updated_at=<Date2017-09-07.23:18:33.573>user='https://github.com/anntzer'
The doc for argparse.RawTextHelpFormatter states that it "maintains whitespace for all sorts of help text, including argument descriptions." But the following example (which outputs "Foo", "Bar", and "Baz", each separated by exactly one empty line) shows that paragraphs separated by more than one empty line will only be separated in the output text by a single empty line.
It maintains *whitespace*, not the new lines.
I've tested this using whitespaces and I think it keeps them according to the original description. See the image attached.
If that is the intended definition of "whitespace" in this context (I have no opinion on that so far), then the docs need amplification, because in general "whitespace" includes newlines. On the other hand, this might be considered a bug in the code and not the docs. However, changing it has backward compatibility implications, so we might go for a doc fix regardless.
I've seen this before, either in another bug/issue or a Stackoverflow question.
The basic change in RawTextHelpFormatter is to turn off the line wrapping for texts like the description. Multiple newlines are preserved at this step.
But after assembling all the pieces (usage, description, help, epilog) the formatter strips out duplicate newlines. This is needed because the process of assembly freely inserts newlines between the pieces, regardless of whether they are blank or not. It can't, or at least doesn't try to, distinguish between newlines within a block like the description, and newlines between blocks.
If someone could come up with a simple patch, great. Or a simple change to the doc wording. But I don't think this issue merits a larger fix.
New changeset 397c467 by R. David Murray (Elena Oat) in branch 'master': bpo-31330: Clarify that RawTextHelpFormatter collapses repeated newlines. (bpo-3272) 397c467
New changeset 82cae7c by R. David Murray (Miss Islington (bot)) in branch '2.7':
[2.7] bpo-31330: Clarify that RawTextHelpFormatter collapses repeated newlines. (GH-3272) (GH-3428) 82cae7c
New changeset e89b35d by R. David Murray (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-31330: Clarify that RawTextHelpFormatter collapses repeated newlines. (GH-3272) (GH-3429) e89b35d
Activity
anntzer commentedon Sep 2, 2017
The doc for argparse.RawTextHelpFormatter states that it "maintains whitespace for all sorts of help text, including argument descriptions." But the following example (which outputs "Foo", "Bar", and "Baz", each separated by exactly one empty line) shows that paragraphs separated by more than one empty line will only be separated in the output text by a single empty line.
Bar
Baz''')
parser.print_help()
elenaoat commentedon Sep 2, 2017
It maintains *whitespace*, not the new lines.
I've tested this using whitespaces and I think it keeps them according to the original description. See the image attached.
bitdancer commentedon Sep 2, 2017
If that is the intended definition of "whitespace" in this context (I have no opinion on that so far), then the docs need amplification, because in general "whitespace" includes newlines. On the other hand, this might be considered a bug in the code and not the docs. However, changing it has backward compatibility implications, so we might go for a doc fix regardless.
paulj3 commentedon Sep 2, 2017
I've seen this before, either in another bug/issue or a Stackoverflow question.
The basic change in RawTextHelpFormatter is to turn off the line wrapping for texts like the description. Multiple newlines are preserved at this step.
But after assembling all the pieces (usage, description, help, epilog) the formatter strips out duplicate newlines. This is needed because the process of assembly freely inserts newlines between the pieces, regardless of whether they are blank or not. It can't, or at least doesn't try to, distinguish between newlines within a block like the description, and newlines between blocks.
If someone could come up with a simple patch, great. Or a simple change to the doc wording. But I don't think this issue merits a larger fix.
paulj3 commentedon Sep 2, 2017
http://bugs.python.org/issue17113
argparse.RawDescriptionHelpFormatter should not delete blank lines
This provides more details on why this is happening.
I suggest using adding a space between newlines, thus: '\n \n'. HelpFormatter.format_help is just looking for '\n\n'.
elenaoat commentedon Sep 6, 2017
I've created a pull request. Could someone review it please?
bitdancer commentedon Sep 7, 2017
New changeset 397c467 by R. David Murray (Elena Oat) in branch 'master':
bpo-31330: Clarify that RawTextHelpFormatter collapses repeated newlines. (bpo-3272)
397c467
bitdancer commentedon Sep 7, 2017
Thanks, Elena.
bitdancer commentedon Sep 7, 2017
New changeset 82cae7c by R. David Murray (Miss Islington (bot)) in branch '2.7':
[2.7] bpo-31330: Clarify that RawTextHelpFormatter collapses repeated newlines. (GH-3272) (GH-3428)
82cae7c
bitdancer commentedon Sep 7, 2017
New changeset e89b35d by R. David Murray (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-31330: Clarify that RawTextHelpFormatter collapses repeated newlines. (GH-3272) (GH-3429)
e89b35d