[issue39167] argparse boolean type bug

Trenton Bricken report at bugs.python.org
Mon Dec 30 12:28:05 EST 2019


Trenton Bricken <brickentrenton at gmail.com> added the comment:

Thank you for your quick and helpful reply. 

The problem with your solution is twofold: 
1. it adds some cognitive load in needing to remember whether or not the flag defaults to True or False and thus whether or not you need to add it. It is easier for me to have everything as a flag with a value that follows. 
2. More importantly, I am using argparse for trying lots of different combinations of inputs to a function so I pass them in as a list and then permute the possible values for each input. 

For example: --flag1 a b
--flag2 c d
 
I want to then run a command with the parameter combinations: 
a, c; a, d; b, c; b, d;

And I don't think store_true store_false would allow me to pass in having combinations of True and False like --flag True False would. 

I am fine now with my current work around, but was very confused for some time why my flag would be true when I set it to false. And think this is a counterintuitive pitfall other developers can fall into.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39167>
_______________________________________


More information about the Python-bugs-list mailing list