[New-bugs-announce] [issue23298] Add ArgumentParser.add_mutually_dependence_group

dongwm report at bugs.python.org
Thu Jan 22 06:41:52 CET 2015

New submission from dongwm:

Sometimes I need to use argparse like this:

>>> parser = argparse.ArgumentParser(prog='PROG')
>>> group = parser.add_mutually_dependence_group()
>>> group.add_argument('--foo')
>>> group.add_argument('--bar')
>>> parser.parse_args(['--foo', 'f', '--bar', 'b'])
Namespace(bar='b', foo='f')
>>> parser.parse_args(['--foo', 'f'])
PROG: error: --foo dependence on --bar
>>> parser.parse_args(['--bar', 'b'])
PROG: error: --bar dependence on --foo

I have some optional argument. but if any argument in a group was present on the command line. i need the others must also was present on. so i think ``add_mutually_dependence_group`` does make sense.

components: Library (Lib)
files: argparse_lib.patch
keywords: patch
messages: 234475
nosy: bethard, dongwm
priority: normal
severity: normal
status: open
title: Add ArgumentParser.add_mutually_dependence_group
type: enhancement
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file37814/argparse_lib.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list