On Fri, 26 Feb 2021 at 02:49, Stephen J. Turnbull <turnbull.stephen...@u.tsukuba.ac.jp> wrote: > > 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.
Given that the hook would just be called after parsing the args would be the advantage of using a hook compared to just validating the args yourself after calling parse_args? Oscar _______________________________________________ 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/UGZKHENX5XG24BV6HAP2H43SRUUSOXCC/ Code of Conduct: http://python.org/psf/codeofconduct/