Karl Richter added the comment:
@paul.j3 That's interesting [1]. Documenting argparse.register seems crucial to
me (- reopen or file a new request?).
After dealing more with the very sophisticated and complex functionality of
argparse I'm sure that this is the only use case where such an
paul j3 added the comment:
In http://bugs.python.org/issue11588#msg212243 I explore the option of using
decorators to 'register' custom functions with the parser. There I was adding
exclusive/inclusive tests, but the same approach could be used to register
custom types and actions.
I
paul j3 added the comment:
Last year someone asked on Stackoverflow about using 'type=bool'. My answer is
at:
http://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse/19233287#19233287
'type' is supposed to be a function that takes a string, and converts to a
desired
Karl Richter added the comment:
That's a pity, I still think it's confusing. Thanks for your feedback!
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21208
___
New submission from Karl Richter:
As arguments with type bool are the only ones whose values can be manipulated
without passing an option to the argument on CLI, the default behavior for
those should be changed from ignoring options to failing when options are
specified. Consider the
Karl Richter added the comment:
I've been mistaken about the behavior if no argument is specified (then the
argument value is None), so this is a bug!
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21208
Josh Rosenberg added the comment:
If your goal is to get a boolean on/off switch, that's what action='store_true'
is for. You don't need to specify nargs or type at all; using bool as the type
means it wants an argument, and will pass the string form of the argument to
the bool constructor;
R. David Murray added the comment:
Yeah, this is a bit non-obvious, but it is a specific instance of the general
way that argparse handles types. So as far as I can see there really isn't
anything to do here.
--
nosy: +r.david.murray
resolution: - invalid
stage: -