New submission from Lucas Cimon <[email protected]>:
Hi!
Here is some minimal code reproducing the issue:
import argparse
common_opts_parser = argparse.ArgumentParser(add_help=False)
common_opts_parser.add_argument("--endpoint", choices=("prod", "dev"),
default="dev")
parser = argparse.ArgumentParser(parents=[common_opts_parser])
subparsers = parser.add_subparsers(required=True)
subcmd_cmd = subparsers.add_parser("subcmd", parents=[common_opts_parser])
subcmd_cmd.add_argument("--debug", action="store_true")
print(parser.parse_args())
Everything works fine / as expected when specifying the common optional arg
last:
$ ./bug_repro.py subcmd --endpoint=dev
Namespace(endpoint='dev', debug=False)
However when specifying the --endpoint between the program and the subcommand,
the value provided is ignored:
$ ./bug_repro.py --endpoint=dev subcmd
Namespace(endpoint=None, debug=False)
I have a PR ready to fix that.
----------
components: Library (Lib)
messages: 408711
nosy: Lucas Cimon
priority: normal
severity: normal
status: open
title: argparse: using parents & subcommands, options can be ignored
type: behavior
versions: Python 3.11
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46101>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com