This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse add_mutually_exclusive_group more than once has incorrectly formatted help
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: bethard Nosy List: bethard, catherine, ddowsett
Priority: normal Keywords: patch

Created on 2010-07-23 14:35 by bethard, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
argparse.diff ddowsett, 2010-07-29 18:53 Patch for Issue9355 in HelpFormatter._format_actions_usage
test_mutually_exclusive.patch catherine, 2010-08-04 20:24 review
mutually_exclusive_help.patch catherine, 2010-08-04 20:26 copy of argparse.diff review
Messages (5)
msg111335 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-07-23 14:35
[Moved from http://code.google.com/p/argparse/issues/detail?id=78]

What steps will reproduce the problem?
1. Create two mutually exclusive groups: eg

agroup = subcmd_parser.add_mutually_exclusive_group()
agroup.add_argument('--a1', action='store_true', help='blah')
agroup.add_argument('--a2', action='store_true', help='blah')
agroup.add_argument('--a3', action='store_true', help='blah')

bgroup = subcmd_parser.add_mutually_exclusive_group()
bgroup.add_argument('--b1', action='store_true', help='blah')
bgroup.add_argument('--b2', action='store_true', help='blah')
bgroup.add_argument('--b3', action='store_true', help='blah')

What is the expected output? What do you see instead?

Expected output (on running a help command which formats help) is:
[ --a1 | --a2 | --a3 ] [ --b1 | --b2 | --b3 ]

You see instead:
[ --a1 | --a2 | --a3 [ --b1 | --b2 | --b3 ]

Note that the closing brace for the first group is missing.
msg111987 - (view) Author: Drake Dowsett (ddowsett) Date: 2010-07-29 18:53
Problem is `inserts' dictionary is overwriting previous closing bracket, so checking for existing value and then appending if found.
msg112884 - (view) Author: Catherine Devlin (catherine) Date: 2010-08-04 20:24
Unit test for Drake's patch
msg112885 - (view) Author: Catherine Devlin (catherine) Date: 2010-08-04 20:26
copy of Drake's argparse.diff - same patch, just has less specific diff header info (because ``patch -p0 < argparse.diff`` failed on my machine)
msg120136 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-11-01 16:31
Committed in r86092 (3.X) and r86093 (2.7). Thanks for the patches!
History
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53601
2010-12-21 10:36:28bethardsetnosy: bethard, ddowsett, catherine
stage: needs patch -> resolved
2010-11-01 16:31:22bethardsetstatus: open -> closed
assignee: bethard
resolution: fixed
messages: + msg120136
2010-08-04 20:26:42catherinesetfiles: + mutually_exclusive_help.patch

messages: + msg112885
2010-08-04 20:24:46catherinesetfiles: + test_mutually_exclusive.patch
nosy: + catherine
messages: + msg112884

2010-07-29 18:53:35ddowsettsetfiles: + argparse.diff
versions: + Python 2.6
nosy: + ddowsett

messages: + msg111987

keywords: + patch
2010-07-23 14:35:22bethardcreate