[New-bugs-announce] [issue13271] When -h is used with argparse, default values that fail should not matter

Joshua Chia report at bugs.python.org
Wed Oct 26 23:25:52 CEST 2011


New submission from Joshua Chia <joshchia at gmail.com>:

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.

----------
components: Library (Lib)
messages: 146458
nosy: Joshua.Chia
priority: normal
severity: normal
status: open
title: When -h is used with argparse, default values that fail should not matter
type: feature request
versions: Python 2.7

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


More information about the New-bugs-announce mailing list