paul j3 added the comment:

Right, the only arguments that a `store_true` Action class accepts are:

     option_strings, dest, default=False,required=False, help=None

parser.add_argument() massages its parameters a bit, and then uses the 'action' 
parameter to construct an Action subclass object with the other parameters.  
Depending on their needs the subclasses may set various defaults or omit 
certain parameters. And without a catchall '**kwargs', the result of providing 
an omitted parameter is this error message.

For 'store_true', a 'type' parameter is superfluous.  It doesn't take any 
arguments (it sets 'nargs=0'), so there aren't any arguments to convert with 
the 'type' function.  It's the Action's own 'default' and 'const' that provide 
the required False and True values.

Also 'bool' is not a meaningful 'type' - for any Action class.  There isn't a 
function in Python converts a string to a boolean.  'bool()' does not do this.  
Or rather, `bool(astr)' converts every string to True except the empty one.

I've seen this mistake before, assuming that 'type=bool' means 'I want the 
result to be a boolean'.  But the docs do say 

    type= can take any callable that takes a single string argument and returns 
the converted value:

'type=float' means 'use float(astr) to convert astr', not 'the argument should 
be a float'.

The documentation is not clear about what parameters are valid for each Action 
type.  It indicates, in bits and pieces, that some parameters are meaningful 
for certain actions, and not useful for others.  One (version) even takes a 
parameter that others don't.  But I haven't seen many bugs - here or on 
StackOverflow - where this is an issue.

----------
nosy: +paul.j3

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

Reply via email to