Issue 13271: When -h is used with argparse, default values that fail should not matter (original) (raw)

Created on 2011-10-26 21:25 by Joshua.Chia, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py Joshua.Chia,2013-03-31 21:32
Messages (6)
msg146458 - (view) Author: Joshua Chia (Joshua.Chia) Date: 2011-10-26 21:25
What steps will reproduce the problem? 1. Make a script containing this code: parser = argparse.ArgumentParser() parser.add_argument('-i', '--input-base-directory', type=argparse.FileType('r'), default='/home') parser.parse_args() 2. Run the script with '-h'. 3. See it complain that '/home' is a directory Detailed explanation: With '-h', we just need to print the help message. We shouldn't fail on a default value that's wrong or else the help message will not get printed and the user will have no idea what the problem is. This is a valid use case as I want to provide a default location, but I can't guarantee that the location works on the user's machine. I end up doing my own checking.
msg146496 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-10-27 15:46
I’d argue this is a behavior bug that could be fixed in 2.7 and 3.2 too, but Steven will decide.
msg146826 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-11-02 06:34
Sounds like a but to me, too.
msg149530 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2011-12-15 11:01
I think http://bugs.python.org/issue12776, which delays type conversions on defaults should solve this problem, right? If you agree, could you add your code here as a test case to that issue and mark this as duplicate? (And yes, I agree this is a bug.)
msg185678 - (view) Author: Joshua Chia (Joshua.Chia) Date: 2013-03-31 21:32
Added test case
msg185680 - (view) Author: Joshua Chia (Joshua.Chia) Date: 2013-03-31 21:34
Seems to be duplicate of http://bugs.python.org/issue12776
History
Date User Action Args
2022-04-11 14:57:23 admin set github: 57480
2013-03-31 21:51:07 eric.araujo set superseder: argparse: type conversion function should be called only oncestage: test needed -> resolved
2013-03-31 21:34:04 Joshua.Chia set messages: +
2013-03-31 21:32:55 Joshua.Chia set status: open -> closedfiles: + test.pyresolution: duplicatemessages: +
2012-03-18 21:39:46 tshepang set nosy: + tshepang
2011-12-15 11:01:57 bethard set messages: +
2011-11-02 06:34:33 petri.lehtinen set stage: test neededmessages: + versions: + Python 2.7, Python 3.2
2011-10-27 15:46:42 eric.araujo set nosy: + eric.araujomessages: + versions: + Python 3.3, - Python 2.7
2011-10-27 12:28:28 petri.lehtinen set nosy: + petri.lehtinen
2011-10-27 01:30:53 eric.smith set nosy: + bethard, eric.smith
2011-10-26 21:25:51 Joshua.Chia create