paul j3 <ajipa...@gmail.com> added the comment:

This is an old topic, though it may be easier to find a relevant StackOverflow 
thread.

https://stackoverflow.com/a/19233287/901925  (a 2013 thread)

I and others have explained that the `type` parameter is supposed to be a 
callable.  The default Python `bool` function only returns False for an empty 
string.  Previous discussions have suggested writing a function that parses 
strings like 'False' and 'No'.  It's nice that you have found a 
'distutils.utils.strtobool' that does this well.

But I have several qualms about the proposed patch:

- do we need to define a 'bool' type?  We already has 'store_true' and 
'store_false' actions.

- does this function need a 'bool' wrapper?

- do we need another import?  There's a relatively recent bug/issue that tries 
to speed up argparse by reducing the number of imports.

- if added, should this type be registered as the object bool or string 'bool'? 
 

Seems to me that the patch could be simplified to:

     self.register('type', 'bool', _strtobool)

According the original developer `type=bool` should be allowed (even if it 
doesn't do what many users expect):

https://bugs.python.org/issue14392

I point out that users are used to providing strings for 'action', but not for 
'type'.  The registry mechanism can be used to provide specialized type but so 
far only 'None' is registered.

https://bugs.python.org/issue26994

https://bugs.python.org/issue24754

This proposed patch might be innocuous, but it does break a consistent behavior 
- that 'type' should be a callable, and 'bool' is a standard Python function.

An alternative is to add to the docs a note (in the 'type' section) that

    from distutils.util import strtobool
    type=strtobool

could be used to parse strings as booleans.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37564>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to