[issue9694] argparse: Default Help Message Lists Required Args As Optional

Ben Schmaus report at bugs.python.org
Thu Aug 26 20:19:19 CEST 2010

New submission from Ben Schmaus <benjamin.schmaus at gmail.com>:

The argparse module lists required args as optional in the default help message.

If you run the following program (also attached) you'll get the output listed below.

#!/usr/bin/env python

import argparse

parser = argparse.ArgumentParser(
    description = 'Do something'
parser.add_argument('--reqarg', '-r', help = 'This is required', required = True)
parser.add_argument('--optarg','-o', help = "This is optional", required = False)
args = parser.parse_args()

$ python argparse-help-says-required-args-are-optional.py -h
usage: argparse-help-says-required-args-are-optional.py [-h] --reqarg REQARG
                                                        [--optarg OPTARG]

Do something

optional arguments:
  -h, --help            show this help message and exit
  --reqarg REQARG, -r REQARG
                        This is required
  --optarg OPTARG, -o OPTARG
                        This is optional

components: Library (Lib)
files: argparse-help-says-required-args-are-optional.py
messages: 115017
nosy: benschmaus
priority: normal
severity: normal
status: open
title: argparse: Default Help Message Lists Required Args As Optional
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file18654/argparse-help-says-required-args-are-optional.py

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list