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 desbma
Recipients barry, desbma, paul.j3
Date 2015-09-14.16:29:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1442248143.45.0.912463017159.issue25061@psf.upfronthosting.co.za>
In-reply-to
Content
> With my type function, the string input is converted to an enum object and that is stored in the Namespace.  You can't be any more direct than that.

Yes I know, but in that case it's missing the autogenerated help message with the possible choices.

I know I can generate it manually, it just does not feel right for doing something so simple. IMO the goal of argparse is to unload the burden of checking/validating parameters manually, generating help messages with default/possible values, etc.

Your solution with a dictionnary is similar to what I currently use and wrote in my example, with the added drawback that the keys are randomly ordered in the help message, unless I use OrderedDict (one more import and more boilerplate code).

Each approach has its drawbacks, unless you write some additional code to workaround each limitation.

In a perfect world, argparse would:
* only show to the user the enum names, and use it in help/error messages, possible choice set, etc.
* after parsing, set the real enum value in the namespace
* and most importantly: to do that, don't require more code than just passing the enum
History
Date User Action Args
2015-09-14 16:29:03desbmasetrecipients: + desbma, barry, paul.j3
2015-09-14 16:29:03desbmasetmessageid: <1442248143.45.0.912463017159.issue25061@psf.upfronthosting.co.za>
2015-09-14 16:29:03desbmalinkissue25061 messages
2015-09-14 16:29:02desbmacreate