classification
Title: Calling argparse add_argument with a sequence as 'type' causes spurious error message
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: bethard Nosy List: bethard, python-dev
Priority: low Keywords:

Created on 2010-07-23 13:27 by bethard, last changed 2011-04-04 00:15 by bethard. This issue is now closed.

Messages (2)
msg111316 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-07-23 13:27
What steps will reproduce the problem?

parser = argparse.ArgumentParser()
parser.add_argument('--foo', type=(int, float))

What is the expected output?

ValueError: (<type 'int'>, <type 'float'>) is not callable

What do you see instead?

TypeError: not all arguments converted during string formatting

Please provide any additional information below.

This is caused by calling using the % string formatting operator without
proper wrapping of the argument. The fix is basically:

-            raise ValueError('%r is not callable' % type_func)
+            raise ValueError('%r is not callable' % (type_func,))
msg132909 - (view) Author: Roundup Robot (python-dev) Date: 2011-04-04 00:14
New changeset f961e9179998 by Steven Bethard in branch '2.7':
Issue #9347: Fix formatting for tuples in argparse type= error messages.
http://hg.python.org/cpython/rev/f961e9179998

New changeset 69ab5251f3f0 by Steven Bethard in branch '3.2':
Issue #9347: Fix formatting for tuples in argparse type= error messages.
http://hg.python.org/cpython/rev/69ab5251f3f0

New changeset 1f3f6443810a by Steven Bethard in branch 'default':
Issue #9347: Fix formatting for tuples in argparse type= error messages.
http://hg.python.org/cpython/rev/1f3f6443810a
History
Date User Action Args
2011-04-04 00:15:33bethardsetstatus: open -> closed
assignee: bethard
stage: needs patch -> resolved
resolution: fixed
versions: + Python 3.3
2011-04-04 00:14:43python-devsetnosy: + python-dev
messages: + msg132909
2010-07-23 13:27:11bethardcreate