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 <>

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")


Everything works fine / as expected when specifying the common optional arg last:

    $ ./ subcmd --endpoint=dev
    Namespace(endpoint='dev', debug=False)

However when specifying the --endpoint between the program and the subcommand, the value provided is ignored:

    $ ./ --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:06Lucas Cimonsetrecipients: + Lucas Cimon
2021-12-16 15:29:06Lucas Cimonsetmessageid: <>
2021-12-16 15:29:06Lucas Cimonlinkissue46101 messages
2021-12-16 15:29:06Lucas Cimoncreate