[Python-Dev] Issue 15906; regression in argparse in Python 3.3, 3.2, and 2.7

Chris Jerdonek chris.jerdonek at gmail.com
Tue Sep 11 19:39:34 CEST 2012

On Tue, Sep 11, 2012 at 10:17 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 9/11/2012 11:34 AM, Barry Warsaw wrote:
>> It seems to me that the semantics could reasonably be implied to mean that
>> the
>> type converter should only be applied to the default value when
>> action='store', as is the default.  Then in the second example, because
>> action='append', the type conversion would not be applied (it makes no
>> sense
>> to do so).
> I arrive at the same conclusion, I believe, by saying that for a given
> parser, the type converter should always or never be applied to 'default',
> which should mean converting or not when the parser is created. Append to
> 'default as base or start' should mean not converting.

I noted this in the comment to the issue, but the argparse
documentation says this about the type argument: "type= can take any
callable that takes a single string argument and returns the converted

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

So type is meant for converting (command-line) strings to other types.
 What is causing one of the problems here is calling type on a
non-string (an empty list in one of the cases above), which doesn't
look like it's meant to be supported..

So another way out could simply be not to call type on non-strings.
Indeed, this was done before.  One of the changes that was made in the
patch for issue 12776 was to remove the str type check prior to
calling type.


More information about the Python-Dev mailing list