[New-bugs-announce] [issue14233] argparse: "append" action fails to override default values

guilherme-pg report at bugs.python.org
Fri Mar 9 01:48:34 CET 2012


New submission from guilherme-pg <guilherme.p.gonc at gmail.com>:

Trying to set a default value to arguments whose action is "append" causes argparse to raise AttributeError when such arguments are provided in the command line (see attached test case t1.py).

This happens because _AppendAction doesn't expect the presence of a default value for the argument: when the command line is parsed and the argument is found, _AppendAction attempts to append the new value to the list of old values, if any, or the old list. In case there is already a non-list default value, it attempts to append the new value to it, which raises the exception.

Is this intended behavior? If so, shouldn't ArgumentError be raised instead? It should also be easy to fix this issue otherwise, making _StoreAction ensure the old values are stored in a list before appending.

----------
components: Library (Lib)
files: t1.py
messages: 155195
nosy: bethard, guilherme-pg
priority: normal
severity: normal
status: open
title: argparse: "append" action fails to override default values
type: crash
versions: Python 3.3
Added file: http://bugs.python.org/file24761/t1.py

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


More information about the New-bugs-announce mailing list