Message408711
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. |
|
Date |
User |
Action |
Args |
2021-12-16 15:29:06 | Lucas Cimon | set | recipients:
+ Lucas Cimon |
2021-12-16 15:29:06 | Lucas Cimon | set | messageid: <1639668546.2.0.488904720024.issue46101@roundup.psfhosted.org> |
2021-12-16 15:29:06 | Lucas Cimon | link | issue46101 messages |
2021-12-16 15:29:06 | Lucas Cimon | create | |
|