New submission from paul j3:

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
Namespace(foo='anyfile')

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].

----------
components: Library (Lib)
messages: 182469
nosy: paul.j3
priority: normal
severity: normal
status: open
title: argparse: Issue 15906 patch; positional with nargs='*' and string default
type: behavior
versions: Python 2.7, Python 3.4

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

Reply via email to