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 avdwoude, paul.j3, rhettinger
Date 2020-10-29.16:39:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603989571.5.0.88301877593.issue42191@roundup.psfhosted.org>
In-reply-to
Content
In the Help formatting, 

    choice_strs = [str(choice) for choice in action.choices]

The use of `repr` in this check_value() error message was, I think, deliberate.  For simple choices like strings and numbers it doesn't matter.  But for other cases, it may help to know more about the identify of the choice objects, such as their class.

The actual parsing test is just a 'in' test.

    value not in action.choices

There is the added complication that the _get_value() function has already applied the type function the argument string, converting it to a compatible object (for testing). 

Should argparse be changed, or should it be up to the developer to use a type/choices pairing that gives the desired help and error messages?

To improve the discussion, I think your 'self.admin' example should be replaced by a self contained type and class.  In the spirit of a StackOverFlow question I'd like concrete minimal example that I can test and play with.  I don't want to write a pseudo-account class.
History
Date User Action Args
2020-10-29 16:39:31paul.j3setrecipients: + paul.j3, rhettinger, avdwoude
2020-10-29 16:39:31paul.j3setmessageid: <1603989571.5.0.88301877593.issue42191@roundup.psfhosted.org>
2020-10-29 16:39:31paul.j3linkissue42191 messages
2020-10-29 16:39:31paul.j3create
Morty Proxy This is a proxified and sanitized view of the page, visit original site.