This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Lucas Cimon
Recipients Lucas Cimon
Date 2021-12-16.15:29:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639668546.2.0.488904720024.issue46101@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-12-16 15:29:06Lucas Cimonsetrecipients: + Lucas Cimon
2021-12-16 15:29:06Lucas Cimonsetmessageid: <1639668546.2.0.488904720024.issue46101@roundup.psfhosted.org>
2021-12-16 15:29:06Lucas Cimonlinkissue46101 messages
2021-12-16 15:29:06Lucas Cimoncreate