classification
Title: Right square bracket argparse metavar
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse assertion failure with brackets in metavars
View: 11874
Assigned To: Nosy List: cortopy, miss-islington, ncoghlan, paul.j3
Priority: normal Keywords:

Created on 2015-09-10 16:30 by cortopy, last changed 2018-06-09 01:28 by miss-islington. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7527 closed miss-islington, 2018-06-08 10:14
PR 7528 merged miss-islington, 2018-06-08 10:14
PR 7530 merged miss-islington, 2018-06-08 11:11
PR 7553 merged miss-islington, 2018-06-09 01:19
Messages (7)
msg250388 - (view) Author: Juan Jimenez-Anca (cortopy) Date: 2015-09-10 16:30
When trying to assign the metavar in add_argument() method of argparse module I'm unable to include characters after a right square bracket.

Trying to set something like this:

metavar="[host:database:collection:]field"

would raise an AssertionError, which includes:

File "/usr/lib64/python3.4/argparse.py", line 329, in _format_usage
    assert ' '.join(opt_parts) == opt_usage

However, the following is accepted:

metavar="[host:database:collection:]field"
msg250389 - (view) Author: Juan Jimenez-Anca (cortopy) Date: 2015-09-10 16:32
My apologies for the formatting of the last line. This is my issue corrected:

When trying to assign the metavar in add_argument() method of argparse module I'm unable to include characters after a right square bracket.

Trying to set something like this:

metavar="[host:database:collection:]field"

would raise an AssertionError, which includes:

File "/usr/lib64/python3.4/argparse.py", line 329, in _format_usage
    assert ' '.join(opt_parts) == opt_usage

However, the following is accepted:

metavar="[host:database:collection:] field"
msg250427 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2015-09-10 22:38
This assertion error caused by brackets (and other 'odd' characters) in the metavar is a known issue.

http://bugs.python.org/issue11874
http://bugs.python.org/issue14046

The formatter that handles line wrapping of the usage line is fragile.
msg319042 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-06-08 10:12
New changeset 66f02aa32f1e4adb9f24cf186f8c495399d5ce9b by Nick Coghlan (wim glenn) in branch 'master':
bpo-11874: fix assertion failure in argparse metavar handling (GH-1826)
https://github.com/python/cpython/commit/66f02aa32f1e4adb9f24cf186f8c495399d5ce9b
msg319051 - (view) Author: miss-islington (miss-islington) Date: 2018-06-08 11:06
New changeset 376c272d68cca0975ff0be3d12abf5f67da342d7 by Miss Islington (bot) in branch '3.6':
bpo-11874: fix assertion failure in argparse metavar handling (GH-1826)
https://github.com/python/cpython/commit/376c272d68cca0975ff0be3d12abf5f67da342d7
msg319055 - (view) Author: miss-islington (miss-islington) Date: 2018-06-08 11:33
New changeset 842985f6c70484ed7b8fc30d0bc05aec73236a98 by Miss Islington (bot) in branch '3.7':
bpo-11874: fix assertion failure in argparse metavar handling (GH-1826)
https://github.com/python/cpython/commit/842985f6c70484ed7b8fc30d0bc05aec73236a98
msg319128 - (view) Author: miss-islington (miss-islington) Date: 2018-06-09 01:28
New changeset 4e6bd247aa955056626bf0cf8dc1c65a587b871f by Miss Islington (bot) in branch '2.7':
bpo-11874: fix assertion failure in argparse metavar handling (GH-1826)
https://github.com/python/cpython/commit/4e6bd247aa955056626bf0cf8dc1c65a587b871f
History
Date User Action Args
2018-06-09 01:28:05miss-islingtonsetmessages: + msg319128
2018-06-09 01:19:26miss-islingtonsetpull_requests: + pull_request7188
2018-06-08 11:33:53miss-islingtonsetmessages: + msg319055
2018-06-08 11:11:23miss-islingtonsetpull_requests: + pull_request7169
2018-06-08 11:06:01miss-islingtonsetnosy: + miss-islington
messages: + msg319051
2018-06-08 10:14:59miss-islingtonsetpull_requests: + pull_request7163
2018-06-08 10:14:00miss-islingtonsetpull_requests: + pull_request7159
2018-06-08 10:12:52ncoghlansetnosy: + ncoghlan
messages: + msg319042
2016-01-17 06:32:01martin.pantersetstatus: open -> closed
superseder: argparse assertion failure with brackets in metavars
resolution: duplicate
2015-09-10 22:38:47paul.j3setnosy: + paul.j3
messages: + msg250427
2015-09-10 16:32:01cortopysetmessages: + msg250389
2015-09-10 16:30:03cortopycreate