-
-
Couldn't load subscription status.
- Fork 33.2k
bpo-44986: Fixed bug with date formats like %Y-%m-%d in help messages of argparse #27923
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
Changes from 12 commits
04f909d
36001c7
d77b2b6
255fa92
cbdc58e
f291df2
8ed8045
cd7aebb
1728042
8697b09
a3be094
02e3b73
60c3e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3934,6 +3934,39 @@ class TestHelpUsageWithParentheses(HelpTestCase): | |||||
| ''' | ||||||
| version = '' | ||||||
|
|
||||||
| class TestHelpWithPercentageSymbols(HelpTestCase): | ||||||
| """Test a help message including % symbols""" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| parser_signature = Sig(prog='PROG', description='Just a test code.') | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| argument_signatures = [ | ||||||
| Sig('--somearg', metavar='somearg', | ||||||
| help='Now you dont need to escape this: %, and you will not get nonsensical errors!'), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Sig('--date', metavar='when', help='A date in format %Y-%m-%d', | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| dest=f'date', type=str, required=True), | ||||||
| Sig('bar', nargs='?', type=int, default=42, | ||||||
| help='the bar to %(prog)s (default: %(default)s)'), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Sig('--weirdarg', metavar='weird', dest=f'weird', type=str, | ||||||
| required=True, help='A weird arg with 1 %, 2 %%% and 3 %%%%%'), | ||||||
| ] | ||||||
|
|
||||||
| usage = '''\ | ||||||
| usage: PROG [-h] [--somearg somearg] --date when --weirdarg weird [bar] | ||||||
| ''' | ||||||
| help = usage + '''\ | ||||||
|
|
||||||
| Just a test code. | ||||||
|
|
||||||
| positional arguments: | ||||||
| bar the bar to PROG (default: 42) | ||||||
|
|
||||||
| options: | ||||||
| -h, --help show this help message and exit | ||||||
| --somearg somearg Now you dont need to escape this: %, and you will not get | ||||||
| nonsensical errors! | ||||||
| --date when A date in format %Y-%m-%d | ||||||
| --weirdarg weird A weird arg with 1 %, 2 %% and 3 %%% | ||||||
| ''' | ||||||
| version = '' | ||||||
|
|
||||||
|
|
||||||
| class TestHelpOnlyUserGroups(HelpTestCase): | ||||||
| """Test basic usage messages""" | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Added feature to argparse so that percentage symbols (%) don't have to be | ||
| escaped in help messages. Without this fix, they have to be escaped (as | ||
| stated in the documentation) but if you forget this, the error message that | ||
| is produced is completely cryptic. With this patch, 1) this does not happen | ||
| anymore, 2) single % don't need to be escaped and 3) it remains fully | ||
| compatible with the previous implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this conditional is redundant, right? Doesn't
replace()handle validating that the string is contained byexpanded_help?