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 Matthijs Kooijman, bethard, paul.j3, porton, rhettinger, zach.ware
Date 2018-08-18.20:55:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1534625745.17.0.56676864532.issue34188@psf.upfronthosting.co.za>
In-reply-to
Content
The 'choices' mechanism is quite simple.  As noted for testing it simply uses an 'in' test.  

For help formating it uses

     choice_strs = [str(choice) for choice in action.choices]
     result = '{%s}' % ','.join(choice_strs)

In other words, it's treated as a iterable. 

But it is easy to produce unmanageable displays, such as with 'range(100)'.  This has been raised in other bug/issues.  The best way around that is with the 'metavar', which lets you customize the 'usage' and 'help'.  One thing that 'metavar' does not help with is the error display.

I'm not privy to the original author's thinking, but I don't think 'choices' was ever meant to be a high power tool.  

With a custom Action you can do almost anything that you could do after parsing.
History
Date User Action Args
2018-08-18 20:55:45paul.j3setrecipients: + paul.j3, rhettinger, bethard, zach.ware, porton, Matthijs Kooijman
2018-08-18 20:55:45paul.j3setmessageid: <1534625745.17.0.56676864532.issue34188@psf.upfronthosting.co.za>
2018-08-18 20:55:45paul.j3linkissue34188 messages
2018-08-18 20:55:45paul.j3create