[issue15906] argparse add_argument() confusing behavior when type=str, default=

Chris Jerdonek report at bugs.python.org
Tue Sep 11 18:15:29 CEST 2012


Chris Jerdonek added the comment:

I'm not sure of all the implications of this, but it seems like this is a relevant piece of information from the docs:

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

(from http://docs.python.org/dev/library/argparse.html#type )

In particular, it doesn't seem like it's meant to be supported to be calling "type" on an argument (e.g. a default argument) that's not a string.  That's what's happening in the code snippet in the first comment above, where the default argument is a list.

I haven't thought about this very long, but what would happen if the "type" conversion is only called on arguments and default arguments that are strings, and otherwise left alone?  It seems like that would at least address the use case in the first comment, and maybe the type=open one as well.

Either way, it seems like you still might need to track whether an argument has been converted (e.g. if type converts string to another string type).

----------
nosy: +cjerdonek

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15906>
_______________________________________


More information about the Python-bugs-list mailing list