[New-bugs-announce] [issue30163] argparse mx_group is required, when action value equal default will be ignore

Louie Lu report at bugs.python.org
Tue Apr 25 22:33:05 EDT 2017


New submission from Louie Lu:

When adding mutually exclusive group and required is True, and the group argument has default value. If we type its default value, argparse will ignore the input and return `argument is required`


------- PoC --------
import argparse

parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-v', type=int, default=10)

print(parser.parse_args())

-----

$ python tests.py -v 10
usage: tests.py [-h] -v V
tests.py: error: one of the arguments -v is required
$ python tests.py -v 11
Namespace(v=11)

----------
components: Library (Lib)
messages: 292293
nosy: louielu
priority: normal
severity: normal
status: open
title: argparse mx_group is required, when action value equal default will be ignore
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30163>
_______________________________________


More information about the New-bugs-announce mailing list