David Mertz writes: > On Wed, Feb 24, 2021 at 1:38 PM Paul Korir <polaris...@gmail.com> wrote: > > > I've been using the argparse library for a long time and one use case that > > repeatedly shows us is the need to have two arguments appear together i.e > > either both appear or none of them appear. I'll refer to these as *mutually > > inclusive* in contrast to the existing *mutual exclusive* feature present. > > I might be wrong but there seems to be no way to enforce this. > > > > I'm of mixed feelings about this. I can absolutely see that it can be > useful, and many tools will have this kind of argument requirement.
Perhaps we could provide a more general facility for validation of the parsed argument values. Of course this would be less convenient for the specific case of arguments that must be specified together with no other requirements, but I wonder how often that case arises. In many cases there are other conditions, for example in specifying an interval, args.lower < args.upper (or <= if you'll accept a degenerate interval). Thing is, this "mutual inclusion" condition isn't really about parsing (ie, syntax)[1]; this is about semantics -- like all input validation. I don't object to having it in argparse, but it's going to be so domain-dependent that I don't think we should do more than provide hooks to validate individual arguments (eg, a 0 <= p <= 1 constraint on probabilities or proportions), and an args.validate hook to do cross-argument validation. Steve Footnotes: [1] I guess we could enforce it as syntax by requiring --foo fval --bar bval in that order. But that's not normally how we think of parsing a command line, and I don't think we want the command line to be a full-blown general parser. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6A4JUSR3DGWDWZ4KJH3ULJGTP4MYTPXG/ Code of Conduct: http://python.org/psf/codeofconduct/