Author paul.j3
Recipients paul.j3
Date 2013-02-20.04:58:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The production argparse applies the type conversion to a string default whether it is needed or not.  With the 12776 and 15906 patch, that conversion is postponed, so that it is applied only once.  However, for a positional argument with nargs='*', that conversion is never applied.

For example, with:
add_argument('foo', type=FileType('r'), default='anyfile', nargs='*')

the development version, with parse_args([]) produces

The previous code tested this default, raising an error if there was an IOError.  But even if it successfully opened the file, the namespace
 would get the string value, not the opened file.

With nargs = '?', the result is an IOError, or an opened file.

It is evident from the code (but not the documentation) that the best
default for the '*' positional is a list of appropriate type of objects.
In the case of FileTypes, about the only choices, without opening a
file, are: [] and [sys.stdin].
Date User Action Args
2013-02-20 04:58:17paul.j3setrecipients: + paul.j3
2013-02-20 04:58:17paul.j3setmessageid: <>
2013-02-20 04:58:16paul.j3linkissue17250 messages
2013-02-20 04:58:16paul.j3create