[issue39167] argparse boolean type bug

paul j3 report at bugs.python.org
Mon Dec 30 14:30:54 EST 2019


paul j3 <ajipanca at gmail.com> added the comment:

Despite the name, the 'type' parameter specifies a function, not a Python class.  

The only string that produces False is the empty one: bool('').  So 'type=bool' is valid Python, even if it isn't useful.

With `nargs='+'` there's no problem with providing strings like 'False', 'true', 'no', 'oui', 'niet', but if you want to convert those to boolean True/False values, you need to write your own 'type' function.


There was a recent bug/issue that proposed providing such a function (or importing it from another module), and shadowing the existing 'bool' function, but that has been rejected (I think).  It isn't really needed, and the proposed solution was too language specific.

Seems to me that expecting your user to provide an open ended list of 'True False False True' strings would be rather confusing, or at least require a complicated 'help' string.  In any case it's not a common enough case to require any changes to the core argparse functionality.

In sum, it isn't clear what the bug is, or what patch you expect.  This sounds more like a StackOverflow question, than a bug report.

----------

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


More information about the Python-bugs-list mailing list