summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorwim glenn <wim.glenn@gmail.com>2018-06-08 10:12:49 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2018-06-08 10:12:49 (GMT)
commit66f02aa32f1e4adb9f24cf186f8c495399d5ce9b (patch)
treea054fae38e3c08132961014dfa76961ac132f326 /Lib/argparse.py
parentff6c07729211fb98431a2793e074d07a21e0650a (diff)
downloadcpython-66f02aa32f1e4adb9f24cf186f8c495399d5ce9b.zip
cpython-66f02aa32f1e4adb9f24cf186f8c495399d5ce9b.tar.gz
cpython-66f02aa32f1e4adb9f24cf186f8c495399d5ce9b.tar.bz2
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
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index e0e367b..a030749 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -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)