homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: When -h is used with argparse, default values that fail should not matter
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse: type conversion function should be called only once
View: 12776
Assigned To: Nosy List: Joshua.Chia, bethard, eric.araujo, eric.smith, petri.lehtinen, tshepang
Priority: normal Keywords:

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:23adminsetgithub: 57480
2013年03月31日 21:51:07eric.araujosetsuperseder: argparse: type conversion function should be called only once
stage: test needed -> resolved
2013年03月31日 21:34:04Joshua.Chiasetmessages: + msg185680
2013年03月31日 21:32:55Joshua.Chiasetstatus: open -> closed
files: + test.py
resolution: duplicate
messages: + msg185678
2012年03月18日 21:39:46tshepangsetnosy: + tshepang
2011年12月15日 11:01:57bethardsetmessages: + msg149530
2011年11月02日 06:34:33petri.lehtinensetstage: test needed
messages: + msg146826
versions: + Python 2.7, Python 3.2
2011年10月27日 15:46:42eric.araujosetnosy: + eric.araujo

messages: + msg146496
versions: + Python 3.3, - Python 2.7
2011年10月27日 12:28:28petri.lehtinensetnosy: + petri.lehtinen
2011年10月27日 01:30:53eric.smithsetnosy: + bethard, eric.smith
2011年10月26日 21:25:51Joshua.Chiacreate

AltStyle によって変換されたページ (->オリジナル) /