[issue46057] argparse: embedded groups may prevent options from being in help output
paul j3
report at bugs.python.org
Mon Jan 10 14:30:34 EST 2022
paul j3 <ajipanca at gmail.com> added the comment:
"I tried to create a group hierarchy in a way that I can pass the responsibility of argument validation to the argument parser."
I looked at your example in:
https://bugs.python.org/issue46058
The many levels of nesting groups was confusing, but now I realize that by nesting argument_groups in a mutually_exlusive_group you were try to implement some sort of any/all group within the xor group.
This cannot be done within argparse. Mutually_exclusive only implements a flat xor. Argument_groups are used for help display, but play no role in parsing.
Some years ago I explored the use of nest parsing groups:
https://bugs.python.org/issue11588
Add "necessarily inclusive" groups to argparse
I was trying to allow for nested groups that implemented all logical options - xor, or, and, not. Defining such groups wasn't hard. And I think I got the testing logic working right. But usage display required too big of a change to the formatter, and left too many loose ends. So I have let that languish.
Now I recommend focusing on doing the testing after parsing. Use meaningful defaults where possible, and use `is None` to test whether a users has provided a value or not.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46057>
_______________________________________
More information about the Python-bugs-list
mailing list