| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Documentation build overview75 files changed · + 1 added · ± 74 modified + Added ± Modified |
Sorry, something went wrong.
There was a problem hiding this comment.
If I understand correctly, this is meant to mirror add_mutually_exclusive_group(). One thing I noticed: the exclusive group rejects a required=True member at setup time (ValueError: mutually exclusive arguments must be optional), but the inclusive group accepts it. I'm wondering how add_mutually_inclusive_group() should behave in that case?
For example, with a non-required group where one member is required=True:
>>> g = p.add_mutually_inclusive_group()
>>> g.add_argument("--foo")
_StoreAction(option_strings=['--foo'], dest='foo', nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)
>>> g.add_argument("--bar", required=True)
_StoreAction(option_strings=['--bar'], dest='bar', nargs=None, const=None, default=None, type=None, choices=None, required=True, help=None, metavar=None, deprecated=False)
>>> p.parse_args([])
usage: [-h] [--foo FOO & --bar BAR]
: error: the following arguments are required: --barSince the group is all-or-nothing, I'd have expected nothing (empty args) to be accepted, but --bar being required makes that impossible. Should this combination be guarded against (like the exclusive group does) or is it intended? Apologies if I'm missing something.
Sorry, something went wrong.
|
@clytaemnestra Good catch - you're right, we need to add a guard to raise if someone tries to add required=True to an argument, since it doesn't really make sense at the member level. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Adds ArgumentParser.add_mutually_inclusive_group(), a flat, symmetric
"all-or-nothing" group: the arguments in the group must either all be
provided together, or none of them.
It mirrors add_mutually_exclusive_group: required=True makes the group
mandatory, usage renders with & (e.g. [--lport LPORT & --rport RPORT]),
and parents=/subparsers are handled.
I have scoped deliberately to the flat, symmetric case and not nested boolean
composition which was deprecated 3.11 / removed 3.14, see #127133.
I'm still collecting some feedback on the issue so leaving this as a draft for now.