[New-bugs-announce] [issue43192] Argparse complains argument required when default is provided

Clint Olsen report at bugs.python.org
Wed Feb 10 05:24:37 EST 2021


New submission from Clint Olsen <clint.olsen at gmail.com>:

When I run the following program, I expect args.run to be 'foo' if no argument is specified on the command-line.

parser = argparse.ArgumentParser()

parser.add_argument('foo', default='bar')

args = parser.parse_args()

$ ./test
usage: test [-h] foo
test: error: the following arguments are required: foo

However if I specify nargs='*' this error goes away.

Maybe I'm missing something obvious, but this seems non-intuitive to me.

----------
components: Library (Lib)
messages: 386770
nosy: Clint Olsen
priority: normal
severity: normal
status: open
title: Argparse complains argument required when default is provided
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43192>
_______________________________________


More information about the New-bugs-announce mailing list