Author cykerway
Recipients cykerway
Date 2016-12-21.00:52:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1482281546.0.0.613026945443.issue29030@psf.upfronthosting.co.za>
In-reply-to
Content
Using `choices` option in `argparse` module caused unwanted behavior.

# Without `choices`

    parser = argparse.ArgumentParser()
    parser.add_argument('length')
    parser.print_help()

## Output

    usage: demo.py [-h] length

    positional arguments:
      length

    optional arguments:
      -h, --help  show this help message and exit

# With choices

    parser = argparse.ArgumentParser()
    parser.add_argument('length', choices=[1,2,3])
    parser.print_help()

## Output

    usage: demo.py [-h] {1,2,3}

    positional arguments:
      {1,2,3}

    optional arguments:
      -h, --help  show this help message and exit

I think the doc says ArgumentParser objects use the `dest` value as the “name” of each object. And the doc doesn't mention anything about `dest` be changed by `choices`. The help text looks ugly when there is a long list of choices.

Currently the problem can be remedied by adding a `metavar` option. But I hope it will be fixed in the library itself.
History
Date User Action Args
2016-12-21 00:52:26cykerwaysetrecipients: + cykerway
2016-12-21 00:52:26cykerwaysetmessageid: <1482281546.0.0.613026945443.issue29030@psf.upfronthosting.co.za>
2016-12-21 00:52:25cykerwaylinkissue29030 messages
2016-12-21 00:52:25cykerwaycreate