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.

Author paul.j3
Recipients bethard, chriz, eric.araujo, ned.deily, paul.j3, pwil3058, python-dev, tshepang, vinay.sajip, zach.ware
Date 2016-08-21.21:35:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471815329.42.0.121266351701.issue12713@psf.upfronthosting.co.za>
In-reply-to
Content
Another failure case:

parser.add_argument('--int', type=int, choices=[10,15,25])

'--int 15` puts 'int=15' in the Namespace.

'--int 2' puts 'int=2' in the Namespace, because it matches the 'str(25)'.

'--int 1' raises an error in the ambiguity error formatting code: 

     'choices': ', '.join(ac)}

This last error could be corrected with:

    'choices': ', '.join(map(repr, ac))

=================

The initial message for this issue stated:

    So that this feature is not foisted on every programmer that uses  
    argparse it could be made an option to the ArgumentParser class with 
    the (possible) additional refinement of specifying a minimum number 
    of characters for the abbreviations.

That was ignored in the subsequent discussion and patches.

Other Choices issues

http://bugs.python.org/issue16468 - argparse only supports iterable choices
http://bugs.python.org/issue16418 - long choices
http://bugs.python.org/issue16977 - choices='abc' case

I recommend closing this issue, and depend on aliases for subparsers abbreviations.  The interaction with 'choices' is just too complicated to handle as proposed here.
History
Date User Action Args
2016-08-21 21:35:29paul.j3setrecipients: + paul.j3, vinay.sajip, bethard, ned.deily, eric.araujo, pwil3058, tshepang, python-dev, chriz, zach.ware
2016-08-21 21:35:29paul.j3setmessageid: <1471815329.42.0.121266351701.issue12713@psf.upfronthosting.co.za>
2016-08-21 21:35:29paul.j3linkissue12713 messages
2016-08-21 21:35:29paul.j3create