bpo-11874: fix assertion failure in argparse metavar handling (GH-1826)

- bugfix and test for fragile metavar handling in argparse (see
  bpo-24089, bpo-14046, bpo-25058, bpo-11874)
- also fixes some incorrect tests that did not make 1-element tuples correctly
This commit is contained in:
wim glenn 2018-06-08 05:12:49 -05:00 committed by Nick Coghlan
parent ff6c077292
commit 66f02aa32f
3 changed files with 40 additions and 10 deletions

View file

@ -327,7 +327,11 @@ class HelpFormatter(object):
if len(prefix) + len(usage) > text_width:
# break usage into wrappable parts
part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
part_regexp = (
r'\(.*?\)+(?=\s|$)|'
r'\[.*?\]+(?=\s|$)|'
r'\S+'
)
opt_usage = format(optionals, groups)
pos_usage = format(positionals, groups)
opt_parts = _re.findall(part_regexp, opt_usage)