New submission from Arnaud Fontaine <ar...@debian.org>:

When specifying a function to be called in type keyword argument of 
add_argument(), the function is actually called twice (when a default value is 
set and then when the argument is given).

While this may not be a problem in most cases (such as converting to an int for 
example), it is an issue for example when trying to open a file whose filename 
is given as a default value but is not accessible for whatever reason because 
the first call will fail whereas only the second should be done. I know this 
may sound like a twisted example but the type function should not be called 
twice anyhow IMHO.

I tested with Python 2.7 and 3.2 from Debian packages only but the bug seems to 
be present in py3k and 2.7 hg branches as well.

I have attached a small script showing the issue and two patches (for 2.7 and 
tip (py3k) hg branches), including an additional test case. All argparse tests 
pass well with 2.7 and 3.2. Hope that's ok.

----------
components: Library (Lib)
files: example-argparse-type-function-called-twice.py
messages: 142306
nosy: arnau
priority: normal
severity: normal
status: open
title: argparse: type conversion function should be called only once
type: behavior
versions: Python 2.7, Python 3.2
Added file: 
http://bugs.python.org/file22926/example-argparse-type-function-called-twice.py

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

Reply via email to