summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-06-08 11:05:58 (GMT)
committerGitHub <noreply@github.com>2018-06-08 11:05:58 (GMT)
commit376c272d68cca0975ff0be3d12abf5f67da342d7 (patch)
treeb7cc3f0203804f36910d54c929e87161b21ea79b /Lib/argparse.py
parenta0accc0f8e747145a3ee36b91338777bc94b3348 (diff)
downloadcpython-376c272d68cca0975ff0be3d12abf5f67da342d7.zip
cpython-376c272d68cca0975ff0be3d12abf5f67da342d7.tar.gz
cpython-376c272d68cca0975ff0be3d12abf5f67da342d7.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 (cherry picked from commit 66f02aa32f1e4adb9f24cf186f8c495399d5ce9b) Co-authored-by: wim glenn <wim.glenn@gmail.com>
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 b69c5ad..1dacb7e 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -325,7 +325,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)