Hi All,

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. Of course it
is possible to have two arguments that are *required* but it's not always
the case that they will be needed.

A more relevant example would be a situation in which you have a set of
mutually exclusive arguments, one of which is a group of arguments. For
example, consider a scenario in which a user is required to enter multiple
related files that share the same file root (excluding the extension). The
program would then infer the various files (co-files) by searching for the
extensions. The first option would have the user only need to provide the
file name root. However, the user may also provide the paths to the various
co-files. In this case, the co-files must occur together but must occur
mutually-exclusively from the file root option.
Another example would be a case in which activating one set of options
implies the need for other options to be simultaneously activated and for
which defaults may not be easily discerned. Quite often the author has to
perform pythonic gymnastics to catch such invalid options, which might be
better handled by the argparse library.

In evaluating the need for this I've come across the following responses:
https://stackoverflow.com/questions/15935092/creating-mutually-inclusive-positional-arguments-with-argparse
https://bugs.python.org/issue11588
https://bugs.python.org/issue23298
https://stackoverflow.com/questions/19414060/argparse-required-argument-y-if-x-is-present
https://www.debugcn.com/en/article/57242307.html
https://picocli.info/#_mutually_dependent_options

I perceive there is a compelling use-case to be addressed here despite an
earlier request being turned down.

With kind regards,
*Paul*
_______________________________________________
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/C3AI2GNYXPTSGGCPTFFI77FQBLMH5GOB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to