Message323732
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. |
|
Date |
User |
Action |
Args |
2018-08-18 20:55:45 | paul.j3 | set | recipients:
+ paul.j3, rhettinger, bethard, zach.ware, porton, Matthijs Kooijman |
2018-08-18 20:55:45 | paul.j3 | set | messageid: <1534625745.17.0.56676864532.issue34188@psf.upfronthosting.co.za> |
2018-08-18 20:55:45 | paul.j3 | link | issue34188 messages |
2018-08-18 20:55:45 | paul.j3 | create | |
|